Temple of The Roguelike Forums

Development => Programming => Topic started by: Pueo on May 29, 2012, 09:56:52 PM

Title: Does nCurses Honor the /n?
Post by: Pueo on May 29, 2012, 09:56:52 PM
A quick yes or no question, does nCurses recognize the /n and act accordingly?

Example:
Code: [Select]
                    move(0, 0);
                    do {
                        curChar = fgetc(highScores);
                        if (curChar == EOF) {
                            break;
                        }
                        else {
                            addch(curChar);
                        }
                    } while ((curChar = fgetc(highScores)) != EOF);
In the addch(curChar) part, if it comes across a newline signal, will it move the cursor to a new line, or do I have to do it manually?
Title: Re: Does nCurses Honor the /n?
Post by: BrightBit on May 29, 2012, 10:36:54 PM
I don't know nCurses, so please ignore me if I'm wrong but are you sure that it is /n? All languages I know use the backslash to indicate an escape sequence, i.e. \n instead of /n. I guess you just made a typo in your post but I just wanted to be sure.
Title: Re: Does nCurses Honor the /n?
Post by: kraflab on May 30, 2012, 03:30:56 AM
I don't know nCurses, so please ignore me if I'm wrong but are you sure that it is /n? All languages I know use the backslash to indicate an escape sequence, i.e. \n instead of /n. I guess you just made a typo in your post but I just wanted to be sure.

Actually, some languages even use '~' fyi.  But it is a moot point because he is talking about the newline "character", not the "\n" string itself.

As to the actual question I don't know ncurses ;)
Title: Re: Does nCurses Honor the /n?
Post by: BrightBit on May 30, 2012, 08:22:05 AM
Actually, some languages even use '~' fyi.

Interesting. I really didn't know that. Thanks.

But it is a moot point because he is talking about the newline "character", not the "\n" string itself.

Yeah, you're right. I was a bit too tired when I wrote this but at least I did no harm by pointing that out.
Title: Re: Does nCurses Honor the /n?
Post by: Pueo on May 30, 2012, 05:47:23 PM
I don't know nCurses, so please ignore me if I'm wrong but are you sure that it is /n? All languages I know use the backslash to indicate an escape sequence, i.e. \n instead of /n. I guess you just made a typo in your post but I just wanted to be sure.
Yeah, well I guess it is \n (I went and looked it up again).

Also, question addendum:
When I make the file, then try and print it (using the same code as above), it skips every other character.  
Example, the first line is: Highscores (Press SPACE to continue)
But it shows: ihcrs(rs PC ocniu)
What am I doing wrong?
Title: Re: Does nCurses Honor the /n?
Post by: kraflab on May 30, 2012, 07:11:00 PM
Look at your code.  Every loop, your while condition reads a character:

while ((curChar = fgetc(highScores)) != EOF)

Then, inside the loop, you read another:

curChar = fgetc(highScores);

And you only print one of them:

addch(curChar);

You have the break condition in the loop already, so it should be while(1).
Title: Re: Does nCurses Honor the /n?
Post by: Pueo on May 30, 2012, 08:11:39 PM
Ah, ok.  I see that now.  
Thanks, kraflab

Also, since you helped me solve that, I now know that nCurses does honor the \n.