Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!rutgers!umn-d-ub!halam2 From: halam2@umn-d-ub.D.UMN.EDU (Haseen I. Alam) Newsgroups: comp.lang.c Subject: Re: How do I make my program beep. Keywords: beep Message-ID: <3527@umn-d-ub.D.UMN.EDU> Date: 8 Jun 90 16:15:11 GMT References: <3472@umn-d-ub.D.UMN.EDU> <1990May27.000808.13551@utzoo.uucp> <1990Jun6.124609.7316@agate.berkeley.edu> <3168@goanna.cs.rmit.oz.au> <43605@ism780c.isc.com> Reply-To: halam2@ub.d.umn.edu (Haseen I. Alam) Organization: University of Minnesota, Duluth Lines: 57 In article <43605@ism780c.isc.com> marv@ism780.UUCP (Marvin Rubenstein) writes: >In article <3168@goanna.cs.rmit.oz.au> ok@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. > > Marv Rubinstein How about using fprintf to print to stderr? A non-ANSI example follows. Even if you redirect the output to a file it will still beep. But probably will not if you send it to /dev/null. I know a lot of people like to have it as a macro, but I have adopted the following, mainly because I can specify how many beeps I want in a call, and 3 in a row almost makes a melody!!!! Haseen. BTW: a BEEP in the right time will save a lot of cries. /* Here comes the three beepers... BEEP-BEEP-BEEP-I-RAY!!!!!!!! */ #include /* #define BELL '\a' /* use it if you got it */ #define BELL '\007' /* or live with what you have */ void beep (times) int times ; { int i, j ; for (i=0; i < times; i++) { fprintf (stderr, "%c", BELL) ; for (j=0; j < 100000; j++) ; /* just a delay */ } fflush (stderr) ; } main () { beep (3) ; } -- .--------------------------------------------------------------------. | Haseen Ibne Alam Tel: (218)-728-2139 | | email : halam1@ub.d.umn.edu or halam@cola.d.umn.edu | `--------------------------------------------------------------------'