Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-23-2011, 11:34 PM   #1
Registered: Feb 2010
Distribution: opensuse 11.2
Posts: 57

Rep: Reputation: 0
problem with a program - ncurses

this is simple program in ncurses, when i run it nothing happend.what is the problem with it??

#include <stdio.h>
#include <string.h>
#include <ncurses.h>

#define WIDTH 30
#define HEIGHT 10 

int startx = 0;
int starty = 0;

int main()
{	int c, choice = 0;
FILE *fp;
fp = fopen ("log.txt", "a");
	WINDOW *menu_win;
	MEVENT event;

	  c = getch();
	  if (c==KEY_MOUSE)
	    /* When the user clicks left mouse button */
	    if(event.bstate & BUTTON1_CLICKED)
	    printf("left click\n");


Last edited by hamedhsn; 01-24-2011 at 09:22 AM.
Old 01-24-2011, 04:16 PM   #2
Registered: Jun 2004
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106

Rep: Reputation: 15
What are you using to compile it? Sometimes when nothing happens it is because you set the project to be a consul and not a windows app at least in Visual C++. I assume the samething might happen with other IDEs.
Old 01-24-2011, 05:41 PM   #3
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Compiling it using
gcc curses.c -o curses -lcurses
and running from a console, when I click I get random letters written to the screen and nothing to log.txt. You can't use printf() reliably (if at all) inside curses in my experience - curses plays with stdout, so it doesn't work as you would expect it to. Also, you have no way to safely close the programme, so the logfile you open never gets closed or flushed, so the logfile will be empty. A better way to test your script would be to either have a way to exit (pressing a key?) which cleans up the logfile, or to use functions like printw() to display debug information... curses style However, this is just guessing at what you mean by "when i run it nothing happend.what is the problem with it??"... You haven't told us:
i) How you compiled it (or even what language you used, but we can guess that. Though we shouldn't have to )
ii) What you expected it to do (I assumed printing the text when you click)
iii) What actually happened

Last edited by Snark1994; 01-24-2011 at 05:45 PM.
Old 01-24-2011, 07:31 PM   #4
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
You're not checking the return value from calling the mousemask() function. You should always check the return value from calling the mousemask() function.


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
[SOLVED] Ncurses based program had to be recompiled on a different PC, same OS tardis1 Programming 6 10-19-2010 09:51 AM
bring up ncurses program through ssh secretlydead Linux - Networking 3 08-17-2009 01:02 AM
how to print text in color by ncurses without opening a ncurses window Greatrebel Programming 0 12-20-2006 09:15 AM
ncurses program gayatri Linux - Software 0 05-03-2004 09:07 AM
compiling program that uses ncurses calble Programming 4 08-10-2003 04:30 PM > Forums > Non-*NIX Forums > Programming

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

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