after exit(1) from curses program, terminal has no text

This is a discussion on after exit(1) from curses program, terminal has no text within the C Programming forums, part of the General Programming Boards category; Hi cprogramming, I have a program where 1. the user can choose to display an ascii pic from three options ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    51

    after exit(1) from curses program, terminal has no text

    Hi cprogramming,
    I have a program where
    1. the user can choose to display an ascii pic from three options
    2. the pic displays in a curses window for, say 10 seconds (10 is a cmd line arg)
    3.the menu of the 3 pics returns
    if the user hits ctrl-c, the program should display a message, wait 3 seconds, then exit (using exit(1)).

    I have a trial program that uses signal(SIGINT, func), that exits fine.
    BUT, when i try a similar func in the middle of a curses program, the signal function exits, BUT then the terminal screen will not show any characters typed in, and the prompt will be LINE-1 COL+1

    I'm new to signals and curses, so I don't know where the problem lies

    here is my test program for signal(SIGINT,func), it works fine
    Code:
    #include<stdio.h>
    #include<signal.h>
    
    void handler(void)
    {
    	printf("timeout!\n");
    	signal(SIGALRM, handler); //reset the action
    	sleep(5); 
    	exit(1);
    }
    
    int main(void)
    {
    	signal(SIGINT,handler); 
    
    	while(1)
    	{
    		printf("PRESS <RETURN>\n");
    		getchar();
    	}
    }
    here is my main and func from the prog that causes terminal to mess up
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<signal.h>
    #include<curses.h>
    
    void func_handler(void)
    {
    	printf("\nquitting in 3 seconds\n");
    	refresh();
    	signal(SIGALRM, func_handler); //reset teh action
    	sleep(3); 
    	
    	exit(1);
    }
    Code:
    #include<stdio.h>
    #include<curses.h>
    #include "lib.h"
    #include <signal.h>
    #include<stdlib.h>
    
    int main(int argc, char *argv[])
    {
    	int delay;
    	
    	signal(SIGINT,func_handler); //set the action
    	
    	
    	
    	
    	sscanf(argv[1],"%d", &delay); //get argv[1] and convert from string to int
    											//using sscanf
    
    	char choice;
    	initscr();
    	choice =' ';
    	do 
    	{
    		move(13,0);
    		addstr("\nPress 1 for Sam,2 for Norm,3 for Rad 4 to quit: ");
    		refresh();
    		
    		choice = getchar();
    		if(choice =='1')
    		{
    			sd();
    			sleep(delay);	
    			
    		}
    		else if(choice =='2')
    		{
    			nd();
    			sleep(delay);
    		}
    		else if(choice =='3')
    		{
    			rei();
    			sleep(delay);
    		}
    	}while(choice != '4');
    	
    	endwin();
    }

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    51
    Solved

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<signal.h>
    #include<curses.h>
    
    void func_handler(void)
    {
    	printf("\nquitting in 3 seconds\n");
    	refresh();
    	signal(SIGALRM, func_handler); //reset teh action
    	sleep(3); 
    	endwin(); //needed this line
    	exit(1);
    }

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You could I believe do:
    Code:
    atexit( endwin );
    But you need really to be calling endwin anyway, in case your program returns normally without you calling exit.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-24-2010, 04:38 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Replies: 1
    Last Post: 12-17-2002, 01:06 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 10:45 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21