Pages

January 20, 2013

Input and Output functions in C-language


input and output printf and scanf codes used in C programming language


INPUT FUNCTION IN C LANGUAGE

getchar( )  

It is used to input a single character from the keyboard. It can only feed character data and no other data type can be feed through this function. It will echo the character on the screen while inputting.
getchar();


getche( ) 

This functions inputs a single character from the keyboard and it will echo that character on the screen but in the next output screen, till that duration that character is saves in computer buffer or memo.
getche();

getch( )  

This function inputs a single character from the keyboard but it will not echo that character on screen rather than it will take the character into computer buffers or memo.
char ch;
getch();


gets( ) 

This function can input a complete character string from the keyboard to computer. This function can include blanks and several characters in the string.
char nm[20];
gets(nm);
How are you?


scanf( )

This function can input any type of data from keyboard to computer. This function can include integer data, floating point and character data from the keyboard.
scanf(“code”,&variable);
where code is different for different data types and a variable is used to input with ‘&’ and this ampersand sign is called address operator.




OUTPUT FUNCTIONS OF C LANGUAGE

putchar( )  

This function will display that character on the string which is already input by using getchar( ) function.
putchar(ch);


putch( )   

This function will also display a single character which has already input by using getch( ) function.
putch(ch);


puts( ) 

This function will display the complete string which user has already input by using the function gets( ).
puts(nm);
it can also display message and after printing the message it will put the cursor in different or next line.
puts(“\n enter any number”);


printf( )   

This function can not only print message, values of variable but it can print both message as well as values of variables. This function has format:
printf(“code”,variable);

1 comment: