Friday, 25 May 2012

basic of getch() and getche() function

getch() function

We use this function for storing a single character value in variable. 

syntex
    
         char ch;
         ch=getch();

int main()
{
    char ch;
    printf("enter value of ch  ");
    ch =getch();
    printf("\n value of ch is \t");
    printf("%c",ch);
}

Input      enter value of ch a 
                  then don't need to hit enter
Output   value of ch is        a


This is simple implementation of getch() function. We can't enter more than one character using getch() function.
Points

  1. we don't need to hit enter after input .

getche() function

We use this function for storing a single character value in variable. 

syntex
    
         char ch;
         ch=getche();
int main()
{
    char ch;
    printf("enter value of ch  ");
    ch =getche();
    printf("\n value of ch is \t");
    printf("%c",ch);
}

Input      enter value of ch (input always invisible)
                 then don't need to hit enter
Output   value of ch is        a


This is simple implementation of getche() function. We can't enter more than one character using getche() function.
Points

  1. we don't need to hit enter after input .
  2.  In case of getche() function we can't see input values



No comments:

Post a Comment