Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How read Linux or Mac created file in Windows via C FILE*?

Tags:

c++

c

file

newline

As all we know in windows EOL is CRLF and in linux LF and CR in Mac. (more_info)

I want to write a program which reads as linux and Mac as well Win files line by line in Windows. To open file I would use fopen in "rt" mode, but I don't know how read lines. fgets reads until CRLF and LF under Windows but I want it to work for EOL=CR files also.

So what is the solution? Thanks in advance.

like image 554
Mihran Hovsepyan Avatar asked Feb 09 '11 14:02

Mihran Hovsepyan


1 Answers

To open in "t" mode, the file must conform to the platform you are running on. Otherwise you just have to open in binary mode, and sort the difference out yourself.

The C library helps you write a program that works roughly the same on different platforms, but does not support "cross reading" the files.

like image 129
Bo Persson Avatar answered Sep 20 '22 05:09

Bo Persson