Re: curses.h, beep() returns ERR, flash() casuses segment fault.

2008-08-28 Thread Thomas Dickey
On Wed, Aug 27, 2008 at 07:10:40PM -0700, 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)
> {

  initscr();/* see also filter() and newterm() */

> if(beep()!=OK)

//> printf("No OK\n"); fflush(stdout);
printw("No OK\n");

> if(flash()!=OK)

//> printf("No Flash\n"); fflush(stdout);
printw("No Flash\n");
  getch();
  endwin();

> return 0;
> }

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net


pgpFLzadHJUGi.pgp
Description: PGP signature


Re: curses.h, beep() returns ERR, flash() casuses segment fault.

2008-08-27 Thread Daniel Molina Wegener
On Wednesday 27 August 2008 22:10:40 Christopher Joyner wrote:
> I do not get the OK from beep, and flash crashes the program.
> This is my code:

  First, take a look on the manual page...
 
>
> #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;
> }

  Well, try:

#include 
#include 
#include 

int
main(int argc,char** argv)
{
/* in curses(3X) manual page... */
initscr();

if (beep() != OK)
printf("No OK\n"); fflush(stdout);
if (flash() != OK)
printf("No Flash\n"); fflush(stdout);
return 0;
}

  And read the curses manual page, you forgot to init
the screen.

>
>
>
> In Love in Jesus Christ, Or Lord and Savior.
>
>
> For God so loved the world, that he gave his only *begotten
> Son, that whosoever believeth in him should not perish, but
> have everlasting life. --John 3:16
>
>
> [SNIP]

Regards,
-- 
 .O. | Daniel Molina Wegener   | C/C++ Developer
 ..O | dmw [at] unete [dot] cl | FOSS Coding Adict
 OOO | FreeBSD & Linux User| Standards Rocks!


signature.asc
Description: This is a digitally signed message part.


Re: curses.h, beep() returns ERR, flash() casuses segment fault.

2008-08-27 Thread Polytropon
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 
> 
> 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, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


curses.h, beep() returns ERR, flash() casuses segment fault.

2008-08-27 Thread Christopher Joyner
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;
}

 

In Love in Jesus Christ, Or Lord and Savior.


For God so loved the world, that he gave his only *begotten Son, that whosoever 
believeth in him should not perish, but have everlasting life.
--John 3:16



  
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"