Thread: Compiler that uses dos.h

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    12

    Compiler that uses dos.h

    this is my code which plays a scale:
    Code:
    #include <stdlib.h>
    #include <dos.h>
    
    void my_sounds(void);
    
    int music(int pitch, int time)
    {
    sound(pitch);
    delay(time);
    nosound();
    return(0);
    }
    
    
    void       my_sounds(void)
     {
          music(130, 2000);
          music(137, 2000);
          music(145, 2000);
          music(155, 2000);
          music(166, 2000);
          music(176, 2000);
          music(185, 2000);
          music(195, 2000);
          music(207, 2000);
          music(220, 2000);
          music(235, 2000);
          music(260, 2000);
          music(275, 2000);
          music(290, 2000);
          music(311, 2000);
          music(333, 2000);
          music(350, 2000);
          music(370, 2000);
          music(390, 2000);
          music(415, 2000);
          music(440, 2000);
          music(470, 2000);
          music(490, 2000);
          music(520, 2000);      
     }
    
    int main(void) {
      my_sounds();      /* <--- this calls the my_sounds() function */
      return 0;
    }

    what free compiler(s) are avaliable to me which use the dos.h header? im currently running xp. the compiler i use at the moment is turbo c v2.01 and this struggles to play the output audio.

    many thanks

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Why do people insist on writing old programs on a new operating system?

    If it's possible, you should write for Windows XP on Windows XP if that is your OS.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Im quite supprised turbo C even installed and ran under XP. I had issue installing MSVC++6.0 at college a while back on WinME. But i guess it all goes down what emulator you have installed.
    Double Helix STL

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    12
    Quote Originally Posted by MacGyver View Post
    Why do people insist on writing old programs on a new operating system?

    If it's possible, you should write for Windows XP on Windows XP if that is your OS.
    thanks for those words of wisdom oh wise one! :-)

  5. #5
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    Well, a compiler called DJGPP works . . . http://www.delorie.com/djgpp/

    Also, MacGyver, the sound() function is _much_ easier to learn and use than the Windows libraries. Why, you don't even have to know what the WinMain() prototype is! (Hint: It's int STDCALL WinMain(HRESULT hInstance, HRESULT hPrevInstance, LPSTR lpCmdLine, int nShow), or APIENTRY under MSVC . . . . That's what I mean.)

  6. #6
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    Quote Originally Posted by kawk View Post
    the sound() function is _much_ easier to learn and use than the Windows libraries.
    Not really, the Beep() function takes identical arguments.
    http://msdn2.microsoft.com/en-us/library/ms679277.aspx
    Generally I agree, but writing functions to replace the old DOS ones isn't that complicated (except probably getch()), plus the FAQ already covers most of these so it's just a matter of Ctrl+C and Ctrl+V.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You do realize you don't need to use WinMain() when using a Windows compiler, correct?

    Code:
    #include <stdlib.h>
    #include <windows.h>
    
    void my_sounds(void);
    
    int music(int pitch, int time)
    {
    	Beep(pitch,time);
    	return(0);
    }
    
    
    void my_sounds(void)
    {
    	music(130, 2000);
    	music(137, 2000);
    	music(145, 2000);
    	music(155, 2000);
    	music(166, 2000);
    	music(176, 2000);
    	music(185, 2000);
    	music(195, 2000);
    	music(207, 2000);
    	music(220, 2000);
    	music(235, 2000);
    	music(260, 2000);
    	music(275, 2000);
    	music(290, 2000);
    	music(311, 2000);
    	music(333, 2000);
    	music(350, 2000);
    	music(370, 2000);
    	music(390, 2000);
    	music(415, 2000);
    	music(440, 2000);
    	music(470, 2000);
    	music(490, 2000);
    	music(520, 2000);
    }
    
    int main(void)
    {
    	my_sounds();      /* <--- this calls the my_sounds() function */
    	return 0;
    }
    Try this on a Windows compiler, and see if this is close enough to what you want.

    Edit: Bleh, someone beat me to suggesting Beep(). lol...

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    12
    Quote Originally Posted by kawk View Post
    Well, a compiler called DJGPP works . . . http://www.delorie.com/djgpp/

    Also, MacGyver, the sound() function is _much_ easier to learn and use than the Windows libraries. Why, you don't even have to know what the WinMain() prototype is! (Hint: It's int STDCALL WinMain(HRESULT hInstance, HRESULT hPrevInstance, LPSTR lpCmdLine, int nShow), or APIENTRY under MSVC . . . . That's what I mean.)
    thanks for the info on that compiler kwak.

  9. #9
    Registered User
    Join Date
    May 2007
    Posts
    12
    Thanks MacGyver that worked on DEV-C++ perfectly, better than when i tried it using a dos compiler. You should be made a saint! certainly wont be using Turbo C v201 anymore thats for sure! Thanks to everyone for their input, now i can create some mad melodies using C! :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM