1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to make computer beep

Discussion in 'C' started by jan1024188, Dec 31, 2006.

  1. jan1024188

    jan1024188 New Member

    Joined:
    Dec 31, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I have a problem....I wrote program which makes computer beep, but there is no beep when executing a program. I included windows.h header, defined speed and wrote following line

    Code:
    Beep(2750, speed);
    Why there is no beep?
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
  3. LaRoza

    LaRoza New Member

    Joined:
    Jul 27, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    I dont know exactly what you want to do, but if you want a beep, use '\a'.

    Here is an example so you can see it:
    Code:
    #include <stdio.h>
    int main(void)
    {
        printf("\a");
        return 0;
    }
    
     
  4. tiger12506

    tiger12506 New Member

    Joined:
    Jun 6, 2007
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    \a does not work in Windows.
    And Beep does not work in non-Windows environments

    Perhaps your frequency of 2750 is higher than you expect, and you are missing it? Try 440. You *will* hear that.

    And what is your value for speed? Make sure that it is at least 500, or you will miss the beep!

    A better name would be 'duration'. (in milliseconds)

    Cheers.
     
  5. LaRoza

    LaRoza New Member

    Joined:
    Jul 27, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    \a works, I just compiled and ran the exact code I posted and it worked fine in Windows XP Pro.
     
  6. HowardL

    HowardL New Member

    Joined:
    Aug 5, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    East Coast USA
    Interesting... I found another in stdlib.h
    I get the same darn ding.wav for all of these though. No change at all...
    I'm in win98 on the old laptop using the mingw gnu C compiler.
    Code:
    #include <stdio.h>            /*  beep1.c  */
    #include <windows.h>
    #include <stdlib.h>
    
    int main(void)
    {
        int i, j, speed = 2000;
    
        printf("1 \a \n");      /* works with just stdio.h */
         Sleep(1000);            /* need windows.h */
                          /* must wait before dings or I won't get ding
                             I guess 'cause it's working so hard to make it: ) */
    
        printf("2  \n");
        putchar(0x07);          /* works with just stdio.h */
        Sleep(1000);
    
        printf("3  \n");
        Beep(2750, speed);      /* need windows.h */
        Sleep(1000); 
        
        printf("4  \n");
        _beep(2750, speed);     /* need stdlib.h */
        _sleep(1000);           /* need stdlib.h */
    
    
        /* I get the same Beep for all of these */
    
        for(i = 400; i <= 2000; i += 400 ) {
          for(j = 400; j <= 2000; j += 400) {
            printf("Beep(%d, %d)  \n", i, j);
            Beep(i, j);
            /* Beep(200, speed); */
            Sleep(1000);
          }
        }
        return 0;
    }
    /*
    Here's where they come from in my mingw - includes directory:
    -----
    winbase.h
    BOOL WINAPI Beep(DWORD,DWORD);
    -----
    stdlib.h
    / *
     * NOTE: Officially the three following functions are obsolete. The Win32 API
     *       functions SetErrorMode, Beep and Sleep are their replacements.
     * /
    _CRTIMP void __cdecl	_beep (unsigned int, unsigned int);
    _CRTIMP void __cdecl	_seterrormode (int);
    _CRTIMP void __cdecl	_sleep (unsigned long);
    */
    
    funny...
    Howard;
     

Share This Page