In this program we use the function 'getchar' to read a character. The getchar function may be called successively to read the characters contained in a line of text.
Warning: The getchar() function accepts any character keyed in. This includes RETURN and TAB.
Would you like to know my name?
Type Y for YES and N for NO: Y
My name is Bond...,JAMES BOND
Would you like to know my name?
Type Y for YES and N for NO: N
You are good for nothing
Warning: The getchar() function accepts any character keyed in. This includes RETURN and TAB.
Output:
#inlcude <stdio.h>
main()
{
char answer;
printf("Would you like to know my name ?\n");
printf("Type Y for YES and N for NO: ");
answer = getchar(); /*...Reading a Character...*/
if(answer == 'Y' || answer == 'y')
printf("\n\n My name is Bond...,JAMES BOND \n");
else
print("\n\n You are good for nothing \n");
}
Would you like to know my name?
Type Y for YES and N for NO: Y
My name is Bond...,JAMES BOND
Would you like to know my name?
Type Y for YES and N for NO: N
You are good for nothing