Archived

This topic is now archived and is closed to further replies.

Joda

UNIX: Handling win linefeeds in a unix app! PANIC!

Recommended Posts

Hey! My app is working with dat files for input. Im reading one float value from every line from my input files. Example Code: do { c = fgets(oneword, 100, fp1); /* get one line from the file */ sscanf( oneword, "%f", &x ); if (c != NULL) printf("%1.2f\n", x ); i++; } while (c != NULL); This works fine as long as I get files from UNIX users but when I get files from win32 users it wont work. I think it has something to do with incorrect linebreaks. Heard that win is using \r\n to mark linebreaks which is strange! So how do I replace "incorrect" linebreaks in my files autmatically? is there any open-source app or something? I triede dos2unix but it wont work... Thanks - Joda

Share this post


Link to post
Share on other sites
Different OS''s have different line terminaters. Write your own version of fgets. For DOS/Windows lines end with \r\n. If I remember correctly Unix ends lines with just \n and Macintosh with just \r.

When I''ve done this in the past the routine I wrote sucked up all chars until it hit a \r or \n. If it was \r then it peeked ahead to see if the next char was a \n and grabbed that to.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
my parser just ignores lines(and \r and \n) completely, but it all depends on what you''re doing

Share this post


Link to post
Share on other sites