getch() problem

getch() problem

Post by Jun Sh » Sun, 31 Oct 1993 01:55:21



I am running the following C program on a HPterminal.
The problem is the line "select a option: " is not displayed on
the screen.  I will not have the problem if I run this program on
a SUN4 Unix machine (Non HP).  Any body have a solution to this problem?
Thanks.

------------------------------ cut here ----------------
#include <curses.h>

char ReadCh()
{
 char c;

 initscr();
 cbreak();
 noecho();
 c = getch();
 endwin();
 return c;

Quote:}

main()
{
 printf("select a option: ");
 ReadCh();
Quote:}

--

 
 
 

getch() problem

Post by Christoph Badu » Tue, 02 Nov 1993 23:49:43



Quote:>I am running the following C program on a HPterminal.
>The problem is the line "select a option: " is not displayed on
>the screen.  I will not have the problem if I run this program on
>a SUN4 Unix machine (Non HP).  Any body have a solution to this problem?
>Thanks.

That is because curses doesn't flush stdout.  Stdio and curses calls
don't mix very well.

If you want to read a character without waiting for the user to press
RETURN, you should do as suggested by answer 4.1 of the
comp.unix.questions FAQ, probably replacing the invocations of stty
with direct manipulations of the terminal driver (see termios/termio
for more information).

--

    Sie reagieren rein mathematish, nicht vernuenftig.
                                -- Cliff Allistair McLane, Orion VIII

 
 
 

getch() problem

Post by Joseph Car » Thu, 04 Nov 1993 23:00:05



>I am running the following C program on a HPterminal.
>The problem is the line "select a option: " is not displayed on
>the screen.  I will not have the problem if I run this program on
>a SUN4 Unix machine (Non HP).  Any body have a solution to this problem?
>Thanks.

>------------------------------ cut here ----------------
>#include <curses.h>

>char ReadCh()
>{
> char c;

> initscr();
> cbreak();
> noecho();
> c = getch();
> endwin();
> return c;
>}

>main()
>{
> printf("select a option: ");
> ReadCh();
>}
>--


Have you tried using the curses print routine 'printw' ?

------

 
 
 

getch() problem

Post by brian.bebe » Sat, 06 Nov 1993 03:24:33




>>I am running the following C program on a HPterminal.
>>The problem is the line "select a option: " is not displayed on
>>the screen.  I will not have the problem if I run this program on
>>a SUN4 Unix machine (Non HP).  Any body have a solution to this problem?
>>------------------------------ cut here ----------------
>>#include <curses.h>

>>char ReadCh()
>>{
>> char c;

>> initscr();
>> cbreak();
>> noecho();
>> c = getch();
>> endwin();
>> return c;
>>}

>>main()
>>{
>> printf("select a option: ");
>> ReadCh();
>>}
>>--

>Have you tried using the curses print routine 'printw' ?

Why should he when curses hasn't even been initialized yet? He has
the initscr() after the printf. I suspect his problem is that he
should either do an 'fflush(stdout);' after the printf or do a
'setvbuf' call before it to unbuffer stdout.

Of course, this is all ignoring the fact that every curses doc warns
you against mixing curses and stdio calls. You should pick one or the
other, although in this small example it should work (but may have problems
printing after the initscr()). If all he needs to do is get a character
in raw mode, curses is kind of overkill. The ioctl on the termio struct
is probably enough. I believe this is covered in the comp.unix.questions
FAQ.

--
======================================================================
Brian Bebeau            |  Interactive Systems (a Systemhouse company)


 
 
 

getch() problem

Post by Christoph Badu » Sat, 06 Nov 1993 22:37:52



Quote:>I suspect his problem is that he
>should either do an 'fflush(stdout);' after the printf or do a
>'setvbuf' call before it to unbuffer stdout.

Even if he did, initscr() clears the screen.

--

        Und dann OVERKILLEN wir sie.    -- Atan Shubashi

 
 
 

1. getch problem

Hello.

I have a problem with the following code. When the user do a choice the
following getchar() function returns imendiately. If i use getch() instead
(under windows) the program runs with no problem. Under Linux using UConio
library it doesn't work. As the getch() function is not an ANSI function ,
i'm wonder for another way to do the same think.
Anybody with any idea on this problem ?

#include <stdio.h>

int main(void) {
    int choice;
    do {
        printf("Your choice ?");
        scanf("%d", &choice);

        switch(choice) {
            case 1:
                 printf("Your choice is 1\n");
                 printf("press any key\n");
                 getchar();
            break;
            case 2:
                 printf("Your choice is 2\n");
                 printf("press any key\n");
                 getchar();
            break;
        }
    } while (choice != 2);
return 0;

Thank you.

2. internet sharing

3. Help getch problems

4. Unix Guru?

5. Problems using getch

6. HELP!! JSP on Solaris

7. problems with getch()

8. Multiple configurations for ONE networkadapter

9. Curses: problem with getch while keypad is set

10. How do I do getch() or getchar() without pressing Enter

11. Writing a getch() function

12. getch() equivalent under linux?

13. getch/getchar/getc