How do I make my program beep.

Dan KoGai dankg at tornado.Berkeley.EDU
Wed Jun 6 22:46:09 AEST 1990


In article <3519 at umn-d-ub.D.UMN.EDU> halam2 at ub.d.umn.edu (Haseen Alam) writes:
>
>>       main() { printf("hello world\7\n"); }
>
> Thank you Mark, you just hit the bulls eye.  Maybe it was a trivial question
> for most C programmers.  But apparantly there are a few of us who are still
> novice, and the net seems a relatively efficient way to get answers to most
> questions.  Specially if the books and the local guru's are of no help.

	It is not a very good idea to make your machine beep via printf().
ASCII 007 is indeed beep but it's just a remainder of old terminal days--this
doesn't work Macintosh and other sophisticated machine--X window has a
capability of suppressing beeps and substitute it to screen flash.  You'd
better write a function|macro to do the task.  It also helps porting over the
system.  Many machines have distinct beep() functions and some can even use
various beeps, such as Macintosh (Mine is Bill and Ted shouting "Exellent!").
	So your function should be:

/* #ifdef UNIX */
#define RETURN '\n' /* for portability. \r for Macintosh, et al */
#define mybeep beep() putchar(\07)	/* Also for portability */
/* endif */

main(){
	....
	printf("hello, world%c", RETURN);
	mybeep();
} 
> One other quick question.  Will '\7' still work on an ANSI compiler?

	Yes it does.  But usually we use octal or hexadecimal for covenience
but any digit followed after '\' is treated as corresponding character.
(ASCII, EBCDIC, whatever).  It can be decimal, octal, or hexadecimal

----------------
____  __  __    + Dan The "Exellent!" Man
    ||__||__|   + E-mail:	dankg at ocf.berkeley.edu
____| ______ 	+ Voice:	+1 415-549-6111
|     |__|__|	+ USnail:	1730 Laloma Berkeley, CA 94709 U.S.A
|___  |__|__|	+	
    |____|____	+ "What's the biggest U.S. export to Japan?" 	
  \_|    |      + "Bullshit.  It makes the best fertilizer for their rice"



More information about the Comp.lang.c mailing list