Hi,
I am having trouble reading a file on DOS. It all worked OK, but we have been presented with files where the records are terminated with (LF)(CR)(LF) instead of the usual (CR)(LF). I am trying to amend it to cope with this.
The program loops over the file as follows:
ftell to get the file position.
fgetc until '\n'(LF) is found.
fseek to get back to the start of the record
fgets to read the record for processing
Start the loop again.
This works fine if the records are terminated with (CR)(LF), but when terminated with (LF)(CR)(LF) the program starts to go backwards in the file for a few iterations and then just stays in the same place. (This is based on printing out what is returned by various calls to ftell.)
Am I doing something fundamentally wrong here or do I just need to debug my code?
One possible way I can see round this is to manipulate the position returned by ftell to point to where it should be. Is this feasible or just totally mad? (It is opened as a text file.)
Any advice would be most welcome.
Thanks.
I am having trouble reading a file on DOS. It all worked OK, but we have been presented with files where the records are terminated with (LF)(CR)(LF) instead of the usual (CR)(LF). I am trying to amend it to cope with this.
The program loops over the file as follows:
ftell to get the file position.
fgetc until '\n'(LF) is found.
fseek to get back to the start of the record
fgets to read the record for processing
Start the loop again.
This works fine if the records are terminated with (CR)(LF), but when terminated with (LF)(CR)(LF) the program starts to go backwards in the file for a few iterations and then just stays in the same place. (This is based on printing out what is returned by various calls to ftell.)
Am I doing something fundamentally wrong here or do I just need to debug my code?
One possible way I can see round this is to manipulate the position returned by ftell to point to where it should be. Is this feasible or just totally mad? (It is opened as a text file.)
Any advice would be most welcome.
Thanks.