Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Curses Troubles!

Status
Not open for further replies.

Skute

Programmer
Jul 21, 2003
272
0
0
GB
Hi,

im having great trouble with the curses library. (Im using Redhat 9.0).

at the start of my program i call:

initscr();
noecho();

then do some printing...

printw("Some stuff here\n");

do while (cQuit != 'q')
{
cQuit = getch();

if (cQuit == 'q')
{
printw("quitting...\n");
}
else
{
printw("you pressed %c\n", cQuit);
}
}



and at the end...

echo();
endwin();


however, when my program terminates, the shell is messed up still! no characters are output as i type and line breaks arent processed properly (the character position moves 1 line down exactly, but doesnt return to left side of screen).

Also, the message "quitting..." never gets displayed on the screen, BUT the message "you pressed %c" does get printed (ie message gets shown as long as it isnt 'q' that gets pressed).

Can anyone tell me what im doing wrong?

Thanks
 
ive managed to sort the above problems out with a quick refresh() in places!


but im having another problem with the curses library which is the dreaded \r\n!

in a normal console, if i do:

printf("Some text\r\n");

it will print the text and then a new line, however, with the curses library, it moves the cursor to the beginning of the line, clears the text, then moves the cursor down.

So if i try:

printf("Some text\r\n");

with the curses library, all that i see is a new line (the cursor moves down).

Is there some sort of flag i can set to stop this? Or is it best to try to reverse the \r\n when using the curses library (reverse by searching the string for \r\n sequence)?
 
Short anwer: You should get rid of the carriage return "\r".

Why: s "\r\n" is the Windows way to separate line, while "\n" is the unix way. In both platforms "\r" (carriage return) means go to the beginning of the current line. "\n" (new line) means move down to the next line. In unix a \n will move to the beginning of the line by itself, but in Windows you're supposed to put a \r in from of it.


I'm guessing that you're either running in unix or using a unix library in windows.


 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top