If my original post had code and files, you would have told me the files were different and how they were different but that in and of itself wouldn't have been enough for me to rewrite my code.
You are assuming how I would have answered. While some of my replies may be terse, I try to make them more useful than simply telling you what the differences are. If were going to do that I may have just posted a suitable command line using 'cmp'.
However, you do have to explain exactly what you want. This is part of the "Be specific" rule of thumb.
If your question basically amounts to "Why doesn't a CR-only line of data stop at the CR when read by fgets()?", then you are asking a "Why? question. The answer to that is a "Because" answer: Because fgets() only stops at newlines.
Your original question ended:
why doesn't fgets stop where it is suppose to?
That's a "Why" question. If that's what you're asking, then I would consider the question answered by a "Because" answer.
Your original question also presupposed that fgets() was supposed to stop at CRs. Which is false. Which I pointed out. Which answered the question "why doesn't fgets stop".
What you posted next was completely unclear as to what you were trying to accomplish.
We can't read your mind. We can't tell if you're looking for an alternate solution or simply an explanation for some observed phenomenon.
If you want a different answer, you should ask a different question.
For example, "How do I get fgets() to stop at CRs?" or "How can I convert my data to LFs so fgets() will stop?". Or simply explain what you want to accomplish: "I want it to stop at CRs, and I don't care if the CR is preserved or not." Now you have defined what you want to happen, which fits the rule of thumb, "Describe what you expect to happen".
You really need to read this, and apply it:
http://www.mikeash.com/getting_answers.html
The condensed version of that essay is summarized in the 4 rules of thumb I already posted. I would only amend "Post your code" to be "Post your code and actual data".
I might not have had to rewrite, if I was told about tr at the point. However, I did make several attempts using preprogrammed code to change the line feeds and carriage returns which failed.
How much of that code did you post? Was that what your "%c\n" attempts were? Because I don't think you ever explained that was what you were trying to do. You simply posted code with no explanation of what goal you were trying to accomplish.
I did mention fgetc() in my first reply. Did you look at it? If, after looking at it, did you consider writing your own function with parameters like fgets(), but which stopped on CR or LF?
fgetc() would make such a function easy to write, because it only works one char at a time. There's also a related ungetc() function in case you read ahead too much. ungetc() is specifically mentioned in fgetc's man page.
If you defined your own function, it's not necessary to rewrite all the occurrances of fgets() to call your new function. The preprocessor can do that automatically:
Code:
#define fgets(a,b,c) my_fgets(a,b,c)
With that macro defined, all occurrances of fgets(some,things,here) will be translated to instead call the function my_fgets().
If you had said you were writing your own replacement for fgets(), but didn't want to change all your code that already used fgets(), I would have told you about writing a macro.
Furthermore, as it turned out there was more wrong with the files than just the difference in end of line characters. I might have never found this out doing it your way.
Or you might have. Or one of us might have. Or you might have quickly solved the line-ending problem and moved on to solve the other problems more quickly.
Once again, we can't read your mind, so if you're having other data problems, we can't possibly know that unless you tell us.