Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   C coding to print the value until next Key Stock? (http://www.go4expert.com/forums/c-coding-print-value-key-stock-t23424/)

jagadesh_61 27Sep2010 12:45

C coding to print the value until next Key Stock?
 
Here i need to get Keybaord input but process should not wait for keybaord input
whenever Key is pressed corresonding action should take place

eg. if first time i pressed '+' the i value should be incremented until
next key is pressed and if '-' is pressed then i value should be decremented
until next key is pressed. pls refer & check complete the following code.
Code:

void main()
{
int i=0;
char ch='*';
while(1)
{
    /* Here i need to get Keybaord input but process should not wait for keybaord input
      whenever Key is pressed corresonding action should take place
       
    eg. if first time i pressed '+' the i value should be incremented until
            next key is pressed    and if '-' is pressed then i value should be decremented
        until next key is pressed.
   
        */
    KeyInput = ReadKeybaordInput();
   
    if(KeyInput == '+')
        printf("\n i=%d",i++);
    else if(KeyInput == '-')
        printf("\n i=%d",i--);
    else if(KeyInput == '*')
        printf("\n i=%d",i);           
    else if(KeyInput == '/')
        exit(0);

}
}


jimblumberg 28Sep2010 02:13

Re: C coding to print the value until next Key Stock?
 
There is no standard 'C' way to do this. It is possible to do it but it is operating system dependent. So please let us know your operating system.

Jim

virxen 28Sep2010 03:02

Re: C coding to print the value until next Key Stock?
 
one way is this

Code:

#include<stdio.h>
#include<conio.h>
int main(){
    int i=0;
   
printf("enter + to increase numbers ,- to decrease any other to pause and / to exit");
printf("\nstarting from %d\n",i);
char a='o';
while(a!='/'){
    while(!kbhit()){
        if (a=='+')
                printf("\n%d",++i);
        else if (a=='-') printf("\n%d",--i);
    }
    a=getch();
}

printf("\nyou pressed / and stopped the process!!!");
getchar();
}

it worked in windows with wxDevcpp compiler.


All times are GMT +5.5. The time now is 09:57.