#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2014
    Posts
    1
    Rep Power
    0

    Help required for file reading line by line and append date


    I have a input file with semi column separated
    ex:

    12345;string1;string2;100;125
    534;string1;string2;12;1256
    etc ....

    I want to read the whole file and append a date and a number to each line in current file.

    ex:-
    12345;string1;string2;100;125;12-April-2012;001
    534;string1;string2;12;1256;13-April-2012;001
    etc..

    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.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    134
    Rep Power
    1
    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.

IMN logo majestic logo threadwatch logo seochat tools logo