April 18th, 2014, 04:10 AM
Help required for file reading line by line and append date
I have a input file with semi column separated
I want to read the whole file and append a date and a number to each line in current file.
can anybody please help/guide how can i do this in C ? i am able to read but append at end of each line is failing for me.
April 18th, 2014, 05:43 AM
Sure. I am assuming this is a text file and you are on windows. I also suspect you were overwriting the data in the next line while trying to append. This might help:
Simply keep buffering the data in 'rb' mode till you hit the carriage-return character ('\x0d' in hex, which marks the end of a line, followed by a line-feed character) or EOF (since the last line might not have the end-of-line signature). Then write this data from memory to a new file opened in 'wb' mode and insert the date or whatever data you want at the end. Insert a carriage-return character followed by a line-feed character again to mark the end of the line. Proceed buffering and writing the data like this till you reach EOF.