I am trying to open a text file which contains a dictionary of english words. Each word and it's definition are on the same line and the entries are delimited by a newline. Now, my question is that if you open a text file using fopen() in "rt" mode then do the newlines have a \r\n or just \n? In binary mode does the newline get interpreted as \r\n or just \n? Massive confusion!
anumash
0
Newbie Poster
Recommended Answers
Jump to PostFrom your question, I assume you are using a Windows system? Do you know if the files are in MS, or in Unix/Linux format?
Jump to PostIn text mode the newline sequence will be converted to '\n', this is true for any platform. In binary mode you're on your own, no translation will occur so on Windows you need to look for and handle newlines in the form of CRLF.
But it's problematic because you can …
Jump to PostOk. On Windows, a text newline ('\n') IS a carriage-return+linefeed ('\r\n') combination. You would only need to use the latter representation if you were reading the file from Unix/Linux systems. On Windows, it is still encoded as '\n'. IE, don't sweat it unless you are reading a file from one …
All 12 Replies
rubberman
1,355
Nearly a Posting Virtuoso
Featured Poster
anumash
0
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
rubberman
1,355
Nearly a Posting Virtuoso
Featured Poster
anumash
0
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
anumash
0
Newbie Poster
anumash
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
anumash
0
Newbie Poster
anumash
0
Newbie Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.