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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fputs problem?

Status
Not open for further replies.

dbsquared

Programmer
Nov 7, 2002
175
US
Here is the problem that I am having:
What I have is a bunch of files that have one line of data in them. What I do is I read the data from the file and fputs it into another file that I collect all the data in.

Here is where the problem comes up. Sometimes the data files have very little data in them and when that happens the fputs put the next files dta in that same line. I used the fputs because it is supposed to put in the CRLF after the string you use but it seems that it doesn't.

It could be my code so here is the code that I am using:

if fopen 0 tempstr READ
fseek 0 0 0 ; Put pointer at end of file.
fread 0 Tempstring 255 Len
fclose 0
if fopen 0 file_name WRITE ; Open file for write only.
statmsg "file %s is open", file_name
fseek 0 0 2; Put pointer at end of file.
fputs 0 tempstring
fclose 0 ; Close the file.
endif
endif

let me know if you see anything wrong.
Thanks a lot!!!

To go where no programmer has gone before.
 
Try changing your fread to fgets. Fgets will strip the carriage return and linfeed from the line that is read, but the fputs will add it back. This can prevent your file from having a double carriage return/linefeed combination.

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top