Thread: problem with while loop using getch function

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    1

    problem with while loop using getch function

    Hey guys
    I'm writting a program that is supposed to play music and i'm having difficulty with turning the music on/off.

    To start the music the user has the press the O key, and to turn it off they press the M key, using on_off = getch(). The music is played by using the random function to select a midi_note, and then looped using the while loop.

    I can get the O button to start the loop, but then can't get the m button to stop it. I'm assuming this is because getch has already assigned O to the on_off.

    Is there a way around this? Sorry, but i'm a bit of a n00b when it comes to programming

    Thanks

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Without seeing what your code looks like, it will be almost impossible to answer.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    71
    Try getche() and see the pressed key, it should print O, M or whatever, if not then the bug prolly is in previous line

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getchar, getch and gets inside while loop
    By sampleandhold in forum C Programming
    Replies: 13
    Last Post: 03-31-2012, 04:18 PM
  2. Getch() like function
    By mr_raging_money in forum C Programming
    Replies: 3
    Last Post: 03-22-2012, 08:59 PM
  3. Problem with for loop calling external function
    By lordbubonicus in forum C Programming
    Replies: 2
    Last Post: 10-13-2007, 10:54 AM
  4. Making a getch and kbhit function?
    By Brian in forum C Programming
    Replies: 2
    Last Post: 03-03-2002, 11:50 AM
  5. Using getch() function
    By BigSter in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2001, 11:05 AM