0

Ok I am planning on making a file for storing data that I will be importing into a program. This program is to be compiled for Linux, Windows, and potentially Mac.

Now what I really want to know is would I need these data files to be slightly different due to the newline character in these files or would stdin not be picky about what system I am on?

Will it be a problem or not? If so what is the proper way to overcome these problems? Also are there any other problems I may be over looking?

PhobicHD
  • 60
  • 10
  • I'm guessing you want to be able to transfer these files between platforms? – Some programmer dude May 30 '13 at 09:03
  • Sorry did I not make this clear? Yes I do and I want to know if a program compiled on windows using stdin will treat the LF and CR LF as the same thing. – PhobicHD May 30 '13 at 09:04
  • Read this, you need to open file in binary format: http://stackoverflow.com/questions/11305479/reading-files-with-dos-line-endings-using-fgets-on-linux – ruben2020 May 30 '13 at 09:14

1 Answers1

0

If the program is not intended to be read by the user, just make sure that you output it in the same form that it will be input. In this case, it may be easier to use a binary format.

Regardless, make sure you set your stream to be binary, otherwise Windows may expand \n into \r\n for text streams.

Alternately, one of the simplest ways to overcome this problem in a platform-agnostic way for text files that are intended to be user-read is to greedily consume all adjacent \r and \n characters as a single line ending, and you won't have to worry about how you output it.

Taywee
  • 1,243
  • 11
  • 15