information about computer technology and about computer languages.

Monday, 22 March 2021

input output functions in C Language

 input 

The process of providing something to the computer is called an input. Program need many certain from the user for working property and Input is mostly given by keyboard. C programing language provides many built in functions to read many given input to computer.
Some important function for input are:
  • Scanf()
The scanf function is used to get function for the user. The input is stored in a variable in a specified form.
Syntax 
scanf(format string, &variable 1, &variable 2, &variable 3 ...)

The variables are used to store the value entered by the user through keyboard.
For Example :
 scanf("%d %f", &n, &avg);
  • gets()
The gets function is used to input string value from the user. The input is stored in a string variable. User can enter any type of letter  including alphabets, digits and special symbols. The null character \0 is automatically entered at the end of string.
The syntax of gets function is 
gets(variable); 
  • getch()
getch stands for get character. The getch function is used to input single character from the user. When this function is executed, it waits for any key to be pressed.
The syntax of getch function is:
getch(); or variable= getch();
  • getche()
getche stands for get character. The letter e in getche stands for echo. The getche function is used to input single character from the user. The echos displays the character on the screen. getche function is defined in the header file conio.h
The syntax of getche function is:
getche();



Output

The process of getting something from the computer is called an output. Output mostly displayed on monitor. C programing language provides many built in functions to show output on monitor/screen. it is necessary to include the header files ( stdio.h) when program uses any input or output functions in program.
Some important functions for output are:
  • Printf()
The printf function is used to print or display output on the monitor. it can display text, values of variables, on the screen in specified format.
Syntax
The syntax of printf function is :
printf( Format string, argument_list);

Format String 

Format string is given in double quotes. it may consist of text, format specifiers and escape sequences. The %d format specifier is used to show the value of integer variables. %c is used to display character, %f for float variables,  %s for  string variables, %lf for double and %x for  hexadecimal variables. 

Argument list

The argument list consist of constants, variables or expressions whose values are to be printed on the  screen. Each argument in the list is separated by comma.
 For Example:
printf("your marks are %d", m); 

  • puts()
The puts function is used to write string on the screen. it can display a string constant. 
Syntax 
puts(parameter);

Parameter 

it indicates the string variable in which the string is stored. In case of string constant, it is written in double quotes.
For Example:
puts("Programing makes life interesting");

No comments:

Post a Comment