|
Input/Output in C
An Introduction |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
<stdio.h>
FILE type for I/OSystem.in, System.out,
and System.err, you can use the
FILE variables stdin,
stdout, and stderr
fopen and fclose Functions:
FILE* fopen(const char* name, char* mode)
int fclose(FILE f)
name is (a pointer to) the name of the filemode is used to control the properties
of the file. A mode of "w" indicates that the file should be
opened for writing (i.e., output) and a mode of "r" indicates that
it should be opened for reading (i.e., input).
printf and scanf
functions (and variants discussed below) for this purposeprintf Function:
scanf Function:
l
for long)
| d, i | Signed integer |
| f | Floating point |
| u | Unsigned integer |
| s | String (i.e., pointer to an array of char) |
| c | Character |
| o | Unsiged octal |
| x | Unsigned hexadecimal |
| e | Floating point in scientific notation |
| p | Pointer (as a character sequence) |
| n | Write the number of characters written so far to the given address |
fprintf Function:
fscanf Function:
FILE to use for
input/output
sprintf function:
printf except that it does not
write to an output device; it stores what would be
printed in the given string
snprintf function:
sprintf except that the maximum number of
characters is specified
fread Function:
fwrite Function: