Author Topic: Does nCurses Honor the /n?  (Read 9582 times)

Pueo

  • Rogueliker
  • ***
  • Posts: 263
  • Karma: +0/-0
    • View Profile
    • Email
Does nCurses Honor the /n?
« 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?
{O.o}
 |)__)
   ” ”   o RLY?

BrightBit

  • Newcomer
  • Posts: 16
  • Karma: +0/-0
    • View Profile
    • My artwork gallery
Re: Does nCurses Honor the /n?
« Reply #1 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.
« Last Edit: May 29, 2012, 11:25:55 PM by BrightBit »

kraflab

  • Rogueliker
  • ***
  • Posts: 454
  • Karma: +0/-0
    • View Profile
    • kraflab.com
Re: Does nCurses Honor the /n?
« Reply #2 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 ;)

BrightBit

  • Newcomer
  • Posts: 16
  • Karma: +0/-0
    • View Profile
    • My artwork gallery
Re: Does nCurses Honor the /n?
« Reply #3 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.

Pueo

  • Rogueliker
  • ***
  • Posts: 263
  • Karma: +0/-0
    • View Profile
    • Email
Re: Does nCurses Honor the /n?
« Reply #4 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?
{O.o}
 |)__)
   ” ”   o RLY?

kraflab

  • Rogueliker
  • ***
  • Posts: 454
  • Karma: +0/-0
    • View Profile
    • kraflab.com
Re: Does nCurses Honor the /n?
« Reply #5 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).

Pueo

  • Rogueliker
  • ***
  • Posts: 263
  • Karma: +0/-0
    • View Profile
    • Email
Re: Does nCurses Honor the /n?
« Reply #6 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.
« Last Edit: May 30, 2012, 08:17:00 PM by Pueo »
{O.o}
 |)__)
   ” ”   o RLY?