Thread: Loop while waiting for input?

  1. #1
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100

    Question Loop while waiting for input?

    Hello, i'm not new to C++ but i havn't coded in a few years, so i'm rather rusty.

    I'm trying to make a do... while. that loops while waiting for a key press. It's for a splash screen. I'm running into the problem that it will wait for input if i use ...while((ch=getch)==0) or even if i use any iteration of that.

    It's for a console program.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Perhaps kbhit()? It really depends on your platform since there is no standard C++ solution for that.

  3. #3
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    edit: That did it.

    I had to us getch() to clear the buffer after kbhit(); but it did work. Thanks!
    Last edited by Terran; 05-22-2008 at 07:33 PM.

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    no no, spawn a second thread to handle keyboard input adn have it signal the main thread when there is input ready lol.

  5. #5
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    you do it and i'll take credit for it!

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    its really not hard to spawn extra threads, but doing so for such a simple task would be like swatting a fly with a sledgehammer.

  7. #7
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    Man this is the first program i've written on my own in like 3 years, it's pretty rough as it is. lol I'll post the full code for criticism when i'm done.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM