DATA INPUT AND OUTPUT
DATA INPUT AND OUTPUT
SINGLE CHARACTER INPUT AND OUTPUT :
- getchar() :
- The getchar() function is used to get a single character from the user.
- At a time it reads only a single character,so if we have entered character say 'xyz' it will only take 'x' as a single character.
- SYNTAX : char variable_name = getchar();
- putchar() :
- The putchar() function is used to print/display the single character that user have entered using getchar() function.
- The function will display only a single character at a time.
- SYNTAX : putchar(variable_name);
#include <stdio.h>
void main()
{
char a;
a=getchar();
putchar(a);
}
SCANF AND PRINTF FUNCTION :
- scanf() :
- The scanf() function is used to get input of any datatype from the user.
- It scans/take input from the user according to the format provided.
- Format specifies the datatypes such as %d,%s,%c,%f for integer,string,character,float.
- SYNTAX : scanf("format",&variable_name);;
- printf() :
- The printf() function is used to print/display string along with the values if required.
- It is used for guiding the user and also to print the values/data.
- SYNTAX : printf("control string format"variable_name);
#include <stdio.h>
void main()
{
int num;
printf("ENTER NUMBER : ");
scanf("%d",&num);
printf("\nTHE NUMBER YOU HAVE ENTERED IS : %d",num);
}
GETS and PUTS function :
- gets() :
- This function is useful to accept from the keyboard and store it into a variable.
- SYNTAX : gets(str);
- puts() :
-
This function displays a string on the monitor.
- SYNTAX :
puts(str);
Comments
Post a Comment