C-programming Reading input
C - Input & Output
printf() ,scanf(),gets(),getchar(),puts() and putchar()
scanf()
This function reads formatted input from standard input (keyboard) printf() This
function sends formatted output to the standard output (screen)
Example 1 C Integer Input/Output
#include <stdio.h>
int main()
{
int n;
printf("Enter an integer: ");
scanf("%d",&n); //Reads intiger from keyboard to variable n
printf("Number = %d",n); //Prints the read value in output screen
return 0;
}
getchar() - This function is used to read single character
putchar() -This function is used to print single character
Example 2 -getchar(),putchar()
#include <stdio.h> int main () { char c; printf("Enter character: "); c = getchar(); printf("Character entered: "); putchar(c); return(0); }
gets()- This function is used to read a string
puts()- This function is used to print a string
Example 3- gets(),puts()
#include <stdio.h> int main() { char str[50]; printf("Enter a string : "); gets(str); printf("You entered :"); puts(str); return(0); }
Comments
Post a Comment