LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 12-22-2004, 02:50 AM   #1
wenta0
LQ Newbie
 
Registered: Dec 2004
Posts: 4

Rep: Reputation: 0
Segmentation fault ( C )


#include <curses.h>
int main()
{
int c;
c = getch();
}


gcc -o test test.c -lcurses
=>
Segmentaion fault.
Help me, thanks.
 
Old 12-22-2004, 03:00 AM   #2
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
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.
 
Old 12-22-2004, 03:38 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Or, in the case you do not really need curses, just do:
Code:
#include <stdio.h>
int main()
{
  int c;
  c = getchar();
}
 
Old 12-22-2004, 05:42 AM   #4
wenta0
LQ Newbie
 
Registered: Dec 2004
Posts: 4

Original Poster
Rep: Reputation: 0
...
...
initscr();
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()?
 
Old 12-22-2004, 06:10 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
This question has been already asked one thousand times in the forum.
Please find one solution here:
http://www.linuxquestions.org/questi...61#post1359661
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what does Segmentation Fault mean ? baronlynx Linux - Newbie 10 10-25-2009 05:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 10:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 12:13 PM
Segmentation fault tejas15_10 Programming 9 06-20-2005 10:12 AM
Segmentation fault santhosh_o Programming 3 10-26-2004 06:45 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration