From owner-freebsd-questions@FreeBSD.ORG Thu Aug 28 04:42:34 2008 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ADA72106567B for ; Thu, 28 Aug 2008 04:42:34 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) by mx1.freebsd.org (Postfix) with ESMTP id 479318FC0C for ; Thu, 28 Aug 2008 04:42:34 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r55.edvax.de (port-92-195-46-249.dynamic.qsc.de [92.195.46.249]) by mx01.qsc.de (Postfix) with ESMTP id A55F750D51; Thu, 28 Aug 2008 06:42:32 +0200 (CEST) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id m7S4gVHj003397; Thu, 28 Aug 2008 06:42:31 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Thu, 28 Aug 2008 06:42:31 +0200 From: Polytropon To: Christopher Joyner 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> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: Christopher Joyner , questions@freebsd.org Subject: Re: curses.h, beep() returns ERR, flash() casuses segment fault. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Aug 2008 04:42:34 -0000 Good morning! On Wed, 27 Aug 2008 19:10:40 -0700 (PDT), Christopher Joyner wrote: > I do not get the OK from beep, and flash crashes the program. > This is my code: > > #include > > 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 #include 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, ...