Scanning character using getchar

Problem statement
Write a c program to scan a character using getchar function
#include<stdio.h>
int main()
{
char a;   /* declairation of this will always be character type */
printf("enter number ");
a=getchar();   /* this assigns the value entered by you to a in */
getchar();      /* this is a dummy getchar,this come always after getchar to take enter because getchar   considers ENTER also as an character */
printf("the character entered by you is %c",a);
return 0;
}

No comments:

Post a Comment