How do I make my program beep.

Michael Meissner meissner at osf.org
Tue Jun 12 00:53:55 AEST 1990


In article <90061017513753 at masnet.uucp>
simon.ewins at f664.n250.z1.fidonet.org (simon ewins) writes:

| > In article <3168 at goanna.cs.rmit.oz.au> ok at goanna.cs.rmit.oz.
| > au (Richard A. O'Keefe) writes:
| >>(2) #define mybeep putchar('\7')
| >>    has a fairly serious defect:  output to stdout is often buffered or
| >>    line-buffered, and '\7' is not a complete record.  You need
| >>       #define mybeep (putchar('\7'), fflush(stdout))
| >>
| > 
| > putchar('\7') has an even more serious defect.  The reason for beeping is
| > to notify the user of the program of something while the program is
| > *running*. There is no guarantee that sending a '\7' to stdout will cause
| > an beep. Stdout may well be a diskfile. The output must be directed to a
| > device that will make a noise that the user can hear.  I know of no
| > portable way to do this.
|  
|  
| How about...
|  cprintf("\a");
| or
|  fprintf(stderr,"\a");

Just as stdout may be a diskfile, so can stderr (ie, with 2>file in
the Bourne Shell, or >&file in the C-shell).  There may be no terminal
attached to the process, or the process may be in the backround, in
which case it may get a stop signal upon attempt to write to the
terminal.

If you really want to write a '\7' to the terminal, open /dev/tty.  Be
prepared for some user somewhere to complain because s/he was running
a modem program in the foreground, and the program was connected to
GNU emacs, and the '\007' caused it to abort the current
operation.....

--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA

Catproof is an oxymoron, Childproof is nearly so



More information about the Comp.lang.c mailing list