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.

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?

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

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.


.

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!

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.