Wednesday, 25 June 2014

How to take input in C

c and c++ tutorials // online learning spot
Now we will have a look on a new aspect, it is taking input in a progam of C:
There are many ways to handle the input task but our very first encounter will be with a simple function called scanf().
It is a function of stdio.h header file.

Let us make a program where we ask user to enter any character key from keyboard and after he enters, we will thank him.

Program

#include<stdio.h>
main()
 {
   printf("Enter a character from keyboard");
   scanf("%c");
   printf("Thank you !!!");
}

Explanation :
  • 1st line of code ask for a character input.
  • Then the code waits for an input.
  • Only after any valid input program prints Thank you !!!
  • We will learn more about scanf in next post.
<<Back        Next>>

No comments:

Post a Comment