Click here to Skip to main content
13,503,785 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am having problem with kbhit() and getch() function.

//word = "Hello";
//Funtion is working fine but when I press a key it doesnot enter if(kbhit()) loop.
//Moreover, I tried _getch() next to "if" loop statement but _getch() is also not working :(
void Game::Print_LetterBox(int x,int y,char* word)
    int size = strlen(word);
    char key;

        key = _getch();
    for(int i=0;i<size;i++)
        Letter_Box( word[i],x + i*34,y,"purple");
        for(int j=0;j&lt;size;j++)
            if(word[j] == key)
                Letter_Box( word[i],x+i*34,y,"red");
    Animated_Character( x + size*34, 540 , 5);

Any help!!
Posted 18-Jan-13 7:39am
Updated 18-Jan-13 7:50am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I think your problem is that if is not a loop - it's a one time conditional test. If the test passes, then the code in the statement (or compound statement) below it is executed. If it isn't then the condition is skipped completely, and execution continues immediately with the next statement. I suspect that you want to use while rather than if which does loop.
saad_lah 18-Jan-13 14:20pm
I google and find that it _getch() or kbhit() doesnot work in directx c++,
OriginalGriff 18-Jan-13 14:59pm
Perhaps next time it would help if you tagged your question as DirectX, or said so in the question itself?
Remember that we can't see your screen, access your HDD, or read your mind :laugh:
saad_lah 18-Jan-13 15:00pm
:/ okay
OriginalGriff 18-Jan-13 15:06pm
It's not a problem - it just helps us to answer you better! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180417.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100