You are not logged in.
Pages: 1
I just switched to Arch, so hi guys!
I'm using Vim to write a c program for school. The program is supposed to simply output a single rot13'd word, followed by a newline. So I did:
fprintf(output, "%s\n", result);
When I opened up the output file though, Vim didn't show a newline. I had to use two '\n' characters to get one line to show up. Exploring around, I found out that when the 'eol' option is set (and it is), vim automatically adds a new line to the file. I'm thinking that this means that Vim will ignore an ending '\n' that I output (replacing it with it's autogenerated one, or maybe it doesn't autogenerate a newline if there already is one?), but it will in fact show up in Visual Studio or whatever my professor uses to run our programs. Is this a safe assumption?
You have to know these things when you're king, you know.
Offline
Yes, it will show up in your professor's VS/editor/what-have-you, assuming he does not also have a similar option enabled.
You can test this with cat:
$ cat some-file
blahblahblah$
would mean there is no newline at the end, whereas
$ cat some-file
blahblahblah
$
would mean there is.
## Actually, I'm not sure. Take what I posted with a grain of salt.
Last edited by Peasantoid (2009-10-25 00:34:34)
Offline
What do you mean by "Vim didn't show a newline"? If you mean there was no blank line at the end of the file, that's expected, given the code. If you open a file without a newline at the end, Vim will explicitly warn you with [noeol] at the bottom of the screen (you can check this by removing the \n from your program and opening the resulting file in Vim).
Every line in a conventional text document ends in a newline. This does not mean that there is a blank line at the end, and Vim would be wrong in displaying one. What would happen if you had a file consisting of nothing but a newline character?
Edit: Peasantoid: If I'm correctly understanding the OP's question, yes, that's right.
Last edited by Trent (2009-10-25 01:11:00)
Offline
What do you mean by "Vim didn't show a newline"? If you mean there was no blank line at the end of the file, that's expected, given the code.
Well, I guess I'm used to editors (the text editor in Visual Studio, for example) where the output of my command would look like
somestring
<blank line>
in the editor. Which, as I've been reading on google, is horribly wrong . The whole issue seems rather needlessly complicated. Anyhow, thanks for the cat tip peasantoid, that will help my peace of mind!
Last edited by nmccrina (2009-10-25 01:45:33)
You have to know these things when you're king, you know.
Offline
Seems that the problem is solved, but a tip that might be relevant: When in doubt, use hexdump to see what's really in the file.
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
Pages: 1