This isn't entirely a programming problem, but it may be at its base, which is why I'm bringing it to you guys.

For my assignment, I have download a .txt file from my prof's webpage, and then have my program open it. The file, when opened in a web browser, appears as follows:

87.0
94.5
55.6
88.0
82.0
91.0
etc.

Basically, a list of grades separated by newline characters. The problem is, when I download it and open it in notepad it appears without the newline characters (ie 87.094.555.688.0...etc.) When I open a stream to the file in Visual Studio 2008, it appears that way as well (w/o the newline characters). It appears correctly if opened in Wordpad. I have tried editing the file in notepad, in which case it will look correct in notepad but still stream to VS2008 w/o the newlines.

I am stumped. If it makes a difference, I am running Windows 7 Ultimate, and I am using
filename = fopen("scores1.txt", "r+");
to open the streams. I have tried opening it as a binary file (rb+ instead of r+) just for kicks, but I get the same result.

For my assignment, I have download a .txt file from my prof's webpage, and then have my program open it. The file, when opened in a web browser, appears as follows:<br />
<br />
87.0<br />
94.5<br />
55.6<br />
88.0<br />
82.0<br />
91.0<br />
etc.<br />

<br />

When you view the source of your post this is what it displays.
There's no newline.
Think about it.

Edited 6 Years Ago by Aia: n/a

But if in notepad, something appears on the next line, doesn't there have to be a /n character? What's /br?

My professor said that there was newline character between every line, is he just flat out wrong?

But if in notepad, something appears on the next line, doesn't there have to be a /n character? What's /br?

Do a test.
Open Notepad.
Write a line; press enter.
Write another line; press enter
One more time. Write a line; press enter.

Do you see a \n anywhere? Are there any new lines?

Edited 6 Years Ago by Aia: n/a

I've uploaded one of the sample files, in case it helps.

Attachments
85.5
73.0
71.0
83.5
80.0
76.0
98.0
79.0
90.0
85.0
96.0
89.0
67.0
92.0
92.0
81.0
85.0
92.5
92.0
94.5
90.0
75.0
96.0
91.0
90.0
91.0
96.0
85.0
82.0
69.0
88.0
72.5
92.0
79.0
85.0
87.0
87.0
96.0
90.0
88.0
53.0
84.5
88.0
95.0
92.0
96.0
93.0
75.5
93.0
72.5
83.0
72.5
92.0
80.0
96.0
88.0
86.5
91.5
63.5
93.0
91.5
99.0
93.0
59.5
86.0
87.0
95.0
67.0
90.0
79.0
60.0
89.0
85.0
76.5
88.0
94.5
87.0
88.5
95.0
89.0
80.5
84.0
90.0
94.0
94.5
88.5
90.0
92.0
85.0
97.0
75.0
79.5
85.0
94.5
95.5
90.5
92.0
51.5
79.0
77.5
72.5
76.5
95.5
76.0
91.0
81.0
95.0
99.0
81.0
85.5
85.0
90.0
91.0
77.0
87.5
100.0
92.0
90.0
68.5
80.0
79.0
82.0
82.0
77.0
92.0
79.0
89.0

Do a test.
Open Notepad.
Write a line; press enter.
Write another line; press enter
One more time. Write a line; press enter.

Do you see a \n anywhere? Are there any new lines?

Ahhh. I see what you're saying now. So, simply pressing enter in notepad won't generate a newline character. Ok. Why does Wordpad recognize it though?

I've uploaded one of the sample files, in case it helps.

The file has been encoded as an Unix text file the contains only the newline which representation can be \n at the end of each line.
Windows text files represent the new line using two characters \r\n Both are invisible when displaying the information.

unix/linux represents a newline character ('\n') as 0x0A, called a LF (line feed) and windows represents a newline character ('\n') as 0x0D 0x0A called a CR LF (carriage return line feed). your professor's file is the unix case.

if, when writing programs in unix, you want your newlines to look like windows newlines, you can write them as '\r\n' to give the CR LF. be careful running this on windows, becasue it will give you CR CR LF (0x0D 0x0D 0x0A)..... and let's not even get started on Macs.

this whole incompatibility issue is historic, and there's a huge explanation about the whys and wherefores if you care to read about it. most text editors can deal with the various formats. Windows Notepad can not. So just be aware of this fact. I avoid using Notepad.

be advised, this whole issue can be a pain in the ass if you let it. just understand and accept the way it is, and don't stress about it.


.

Edited 6 Years Ago by jephthah: n/a

unix/linux represents a newline character ('\n') as 0x0A, called a LF (line feed) and windows represents a newline character ('\n') as 0x0D 0x0A called a CR LF (carriage return line feed). your professor's file is the unix case.

if, when writing programs in unix, you want your newlines to look like windows newlines, you can write them as '\r\n' to give the CR LF. be careful running this on windows, becasue it will give you CR CR LF (0x0D 0x0D 0x0A)..... and let's not even get started on Macs.

this whole incompatibility issue is historic, and there's a huge explanation about the whys and wherefores if you care to read about it. most text editors can deal with the various formats. Windows Notepad can not. So just be aware of this fact. I avoid using Notepad.

be advised, this whole issue can be a pain in the ass if you let it. just understand and accept the way it is, and don't stress about it.


.

Ok everyone, thanks for the help. I understand the problem quite well now and I think the bottom line is my prof. is just not specific enough. Wish me luck!

This question has already been answered. Start a new discussion instead.