Good morning!

On Wed, 27 Aug 2008 19:10:40 -0700 (PDT), Christopher Joyner <[EMAIL 
PROTECTED]> 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, ...
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to