-   Programming (
-   -   Segmentation fault ( C ) (

wenta0 12-22-2004 01:50 AM

Segmentation fault ( C )
#include <curses.h>
int main()
int c;
c = getch();

gcc -o test test.c -lcurses
Segmentaion fault.
Help me, thanks.:study: :confused:

bm17 12-22-2004 02:00 AM

google "curses getch". Google is your friend.

You need to call iniscr() first to create the default window. getch() is like wgetch() but it assumes the default window, which you haven't initialized. You can't make assumptions with C. It is a low-level language.

jlliagre 12-22-2004 02:38 AM

Or, in the case you do not really need curses, just do:

#include <stdio.h>
int main()
  int c;
  c = getchar();

wenta0 12-22-2004 04:42 AM

int i = 0;
while ((inBuf[i++] = getch())!= '\n')
printw(" * ");

It seems that initscr() will clear the whole screen.

I am using getch() only to get password from user(another program will call this getpassword() function),
so there is no need to clear the screen or create a new window to get password.

How to keep all the things on the screen but use getch()?

jlliagre 12-22-2004 05:10 AM

This question has been already asked one thousand times in the forum.
Please find one solution here:

All times are GMT -5. The time now is 10:20 PM.