Write a program in C to read a character from terminal.

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.


#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");
}

Output:

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

0 comments:

Post a Comment

 

About Me

It's Me!Hi, I'm Moinuddin. I'm a Software Engineer at WIPRO working on Microsoft .NET Technology. I'm interested in a wide range of technology topics, mainly Microsoft including Windows Azure, WCF, WPF, Silverlight and any other cool technology that catches the eye.

Site Info

ProjectCSharp.com is mainly about demonstrating real time examples in different technologies like ASP.NET, WCF, WPF, Silverlight, Azure etc..,

Followers

Help Links

Project CSharp (C#) Copyright © 2011. All Rights Reserved.