example c program that does "beep"
Thomas Dickey
dickey at radix.net
Sat Dec 26 16:50:14 UTC 2009
On Sat, Dec 26, 2009 at 03:33:27PM +0000, Anton Shterenlikht wrote:
> On Fri, Dec 25, 2009 at 08:49:14PM +0100, Polytropon wrote:
> > On Fri, 25 Dec 2009 18:58:26 +0000, Anton Shterenlikht <mexas at bristol.ac.uk> wrote:
> > > How can I get a beep from c?
> > > I looked at curses and syscons.c, but
> > > still not clear.
> >
> > If you want to use NCURSES / CURSES, it's a bit complicated.
> >
> > Otherwise, just output %c (the character) 0x07, BEL, which
> > generates an audible bell, or beep.
> >
> >
> > *** text/plain attachement has been stripped *** RETRY ***
> >
> > /* beepflash.c
> > * -----------
> > * cc -Wall -lcurses -o beepflash beepflash.c
> > *
> > */
> >
> > #include <stdio.h>
> > #include <ncurses.h>
> >
> > int main(int argc, char *argv[])
> > {
> > initscr();
> > cbreak();
> > noecho();
> > nonl();
> > intrflush(stdscr, FALSE);
> > keypad(stdscr, TRUE);
> > start_color();
> >
> > printf("beep: %d\n", beep());
> > fflush(stdout);
> >
> > printf("flash: %d\n", flash());
> > fflush(stdout);
> >
> > return 0;
> > }
>
> Instead of a beep and a flash I get:
>
> beep: 0./beepflash
> flash: 0
> HAMOR>
That sounds about right, given the code shown above.
If you'd used just
beep();
refresh();
instead of the printf/fflush, it would clear the screen and beep - if the
terminal description says it can do the beep.
In the ncurses sources, progs/clear.c is a simple program which sets
up the terminal and calls the tputs function - something like what you're
trying to do.
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20091226/b4322f4d/attachment.pgp
More information about the freebsd-questions
mailing list