Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

^M after fwrite How to?

Status
Not open for further replies.

DMS500Tech

Technical User
Dec 22, 2004
39
US
I am having trouble formating an output file using "fwrite"
Fwrite is being used with varibles and strings "text"
The data is being written to the output file, just not the way I want it to.

I cannot figure out how to send a carriage return at the end of each fwrite.

This is basically a script to output the results in a structured form so it can be used as a script in another program.

No matter what I try the output wants to come out in random formats with a lot of tabs inserted between writes in what seems to be random also.

Here is a sample of the code I am using.

fwrite 0 asignvp 30 ;"asgnvphem,vp," VPid
pause 1
fwrite 0 correlate 30 ;"correlate,"AcctNum","VPid
pause 1
fwrite 0 "y" 1
pause 1
fwrite 0 catv 30 ;"catv,vp,"VPid,off"
pause 1
fwrite 0 "y" 1
pause 1

I am using a pause so I don't overflow the buffer. At first I was having a problem with partial strings being written.
The pause seems to have fixed that problem.

Any suggestions would be greatly appreciated.
 
Fwrite does not add a carriage return and linefeed to the end of the line, but the fputs command (if you opened or created the file using the TEXT parameter) will do so. Otherwise, you will need to add a `r to the end of each line you write using fwrite to force a carriage return.


 
Thanks for the suggestion Knob.

I knew about fputc but had over looked fputs.
The script was changed to fputs instead of fwrite and "TEXT" was added after create for the fopen command.

Now it works like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top