Date: Thu, 28 Aug 2008 06:42:31 +0200 From: Polytropon <freebsd@edvax.de> To: Christopher Joyner <chris27wjoyner@gmail.com> Cc: Christopher Joyner <chris27wjoyner@yahoo.com>, questions@freebsd.org Subject: Re: curses.h, beep() returns ERR, flash() casuses segment fault. Message-ID: <20080828064231.110a9e80.freebsd@edvax.de> In-Reply-To: <898452.32176.qm@web56714.mail.re3.yahoo.com> References: <898452.32176.qm@web56714.mail.re3.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Good morning! On Wed, 27 Aug 2008 19:10:40 -0700 (PDT), Christopher Joyner <chris27wjoyner@yahoo.com> wrote: > I do not get the OK from beep, and flash crashes the program. > This is my code: > > #include <curses.h> > > int main(int argc,char** argv) > { > if(beep()!=OK) > printf("No OK\n"); fflush(stdout); > if(flash()!=OK) > printf("No Flash\n"); fflush(stdout); > return 0; > } First of all, fflush seems to need a definition from stdio.h. I'm not sure if it's included by default (such as -lc is). I tried to link with -lcurses and -lncurses and I can reproduce the error you mentioned: /* beepflash.c */ #include <stdio.h> #include <curses.h> int main(int argc, char **argv) { printf("beep: %d\n", beep()); fflush(stdout); printf("flash: %d\n", flash()); fflush(stdout); return 0; } % cc -Wall -lncurses -o beepflash beepflash.c % ./beepflash -1 Segmentation fault (core dumped) Allthough I did a lot of programming with NCurses, I'm not sure where this error comes from. My old programs do work with the ncurses installation I have (compile + run), but none of them uses flash() or beep(). I found out that no ncurses package is installed. So I did # pkg_add -r ncurses to install devel/ncurses (ncurses-5.6_2) and repeated the compile process - same result. So I went to check the main difference between my working programs and your code, because I noticed that if I put a beep() and a flash() call into my program, they worked as expected. Solution: Prior to any call to the ncurses library, put these into your code: initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); start_color(); I'm not sure which are essential to make beep() and flash() work as expected, but you can easily find out which ones you don't need. Explaination: The ncurses library / seesion doesn't seem to be initialized correctly, that's why beep() didn't work and flash() caused a segmentation fault. -- Polytropon >From Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080828064231.110a9e80.freebsd>