Thread: J3Op4RdY

  1. #1
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231

    J3Op4RdY

    Flashy title? I know. I made this thread in the C programing section because its about a program that I programed in C. What is it? Its a program that plays the jeopardy theme song then some random stuff here is the code.

    (turn down the volume if you are in a computer lab or something if you dont want everyone to wonder if your the awesomest person in the world)

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    main()
    {
          int int1 = 1;
          int beeper = 2000;
          
          while(int1 == 1 || int1 == 2)
          {
          beep(500,500);
          beep(700,500);
          beep(500,500);
          beep(300,500);
          beep(500,500);
          beep(700,500);
          beep(500,1000);
          sleep(100);
          beep(500,500);
          beep(700,500);
          beep(500,500);
          beep(700,500);
          beep(900,800);
          beep(700,220);
          beep(500,220);
          beep(400,220);
          beep(350,220);
          beep(300,220);
          sleep(100);
          int1++;
          }
          
          printf("rANdOm TiMe :D");
          beep(422,324);
          beep(234,242);
          beep(324,335);
          beep(243,914);
          beep(924,219);
          beep(204,424);
          beep(324,234);
          beep(204,753);
          beep(490,10);
          beep(5000,10);
          beep(320,32);
          
          while(beeper > 0)
          {
                     
                     beep(beeper,10);
                     beeper=beeper - 20;
                     printf("%d\n",beeper);
                     
          }
          
          
          }

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    doesn't compile, says undefined reference to beep. Do I need to link something?

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Thanks.

  4. #4
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198

    Unhappy

    1>------ Build started: Project: test, Configuration: Debug Win32 ------
    1>test.obj : error LNK2019: unresolved external symbol _sleep referenced in function _main
    1>test.obj : error LNK2019: unresolved external symbol _beep referenced in function _main
    1>C:\C Prog\Examples\test\Debug\test.exe : fatal error LNK1120: 2 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    "A word to the wise"

  5. #5
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    If it cant compile with the sleep function in it just take it out. it isnt that important.
    (it works with dev-c++) I thought the sleep function was in the stdlib.h file. I will attach mine.
    hope it works

    Oops I said sleep function. I ment beep
    yea that doesn't need any .h file I think.

    just wait I found something at MSDN
    hope it helps.
    Last edited by xniinja; 08-19-2010 at 07:40 PM.

  6. #6
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198

    Smile

    ok, I'll give it a try. :-)

  7. #7
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    sleep() is not part of standard C library if i'm not wrong.
    Header file only contains function prototype.

  8. #8
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    That sucks. sorry if you cant use this

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I replaced "beep" with "sound( ); delay( ); nosound(); ", since my compiler doesn't support "beep".

    I added also the include file <dos.h> for sound() and nosound().

    It's a little tedious with the editing, but what's left is basically just to transfer over the number for sound() (like 500), and delay() (which is now the second number in the "beep" function call.

  10. #10
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    can you post your code so other people that don't have compilers that support beep can run it?

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    /* plays the theme from Jeopardy game show (more or less) ;)
    
       Compiles and runs on Turbo C (and possibly other compilers
       as well).
    
      For MS compilers, you may need to replace "delay" (which gives
      me ms's of delay), with "sleep". MS compilers are the opposite
      of Turbo C with delay and sleep functionality.
    
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <dos.h>
    
    
    int main()
    {
          int int1 = 1;
          int beeper = 2000;
          
      while(int1 == 1 || int1 == 2)
      {
        sound(500); delay(500); nosound();
        sound(700); delay(500); nosound();
        sound(500); delay(500); nosound();
        sound(300); delay(500); nosound();
        sound(500); delay(500); nosound();
        sound(700); delay(500); nosound();
        sound(500); delay(1000);nosound();
        delay(100);
        sound(500); delay(500); nosound();
        sound(700); delay(500); nosound();
        sound(500); delay(500); nosound();
        sound(700); delay(500); nosound();
        sound(900); delay(800); nosound();
        sound(700); delay(220); nosound();
        sound(500); delay(220); nosound();
        sound(400); delay(220); nosound();
        sound(350); delay(220); nosound();
        sound(300); delay(220); nosound();
        delay(100);
        int1++;
      }
    
               
        printf("rANdOm TiMe :D");
        sound(422); delay(324); nosound();
        sound(234); delay(242); nosound();
        sound(324); delay(335); nosound();
        sound(243); delay(914); nosound();
        sound(924); delay(219); nosound();
        sound(204); delay(424); nosound();
        sound(324); delay(234); nosound();
        sound(204); delay(753); nosound();
        sound(490); delay(10);  nosound();
        sound(5000); delay(10); nosound();
        sound(320); delay(32); nosound();
          
      while(beeper > 20)
      {
        sound(beeper); delay(100); nosound();
        beeper=beeper - 20;
        printf("%d\n",beeper);
      }
      return 0;      
    }

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by xniinja View Post
    can you post your code so other people that don't have compilers that support beep can run it?
    Adak uses another old, deprecated, non-standard compliant compiler that no one else has or uses. Therefore, any code that Adak posts is not standard compliant and sometimes won't compile for other people who keep their compilers up to date.
    Keep that in mind.
    Adak's example is a broken mess; as is yours, because you both use non-standard libraries that not all platforms have and not all compilers implement.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    Yea I figured that out when I tried to compile it in my compiler. oh well I was just having fun anyway.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, using them is fine so long as you're aware of the consequences.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    @Xninja, your compiler doesn't have dos.h?

    Your compiler will use sleep() instead of delay(), to get the timing right.

    Which brings me to the best code comment I've seen:

    /*
    True story: 7 Hz is the resonant
    frequency of a chicken's skull cavity.
    This was determined empirically in
    Australia, where a new factory
    generating 7-Hz tones was located too
    close to a chicken ranch: When the
    factory started up, all the chickens
    died.
    */

    which is included with the nosound() explanation and sample program, in Turbo C/C++.

    General consensus on the web - it's a myth. But this happened before the web began, and sounds pretty specific to be a myth.

    Researchers in this area, have found various sound and RF frequencies which are painful or worse, to soldiers and researchers alike.

Popular pages Recent additions subscribe to a feed