I/Oinc: Engineering H192 - Computer Programming
I/Oinc: Engineering H192 - Computer Programming
I/O in C
Lecture 6
Input/Output in C
Streams
• All input and output is performed with streams.
Types of Streams in C
Input/Output in C
scanf ( ) ;
• This function provides for formatted input from the
keyboard. The syntax is:
scanf ( “format” , &var1, &var2, …) ;
• The “format” is a listing of the data types of the
variables to be input and the & in front of each variable
name tells the system WHERE to store the value that is
input. It provides the address for the variable.
• Example:
float a; int b;
scanf (“%f%d”, &a, &b);
Input/Output in C
getchar ( ) ;
char ch;
ch = getchar ( ) ;
Input/Output in C
putchar (char) ;
char ch;
ch = getchar ( ) ; /* input a character from kbd*/
putchar (ch) ; /* display it on the screen */
Input/Output in C
getc ( *file ) ;
Input/Output in C
Today’s Assignment