Some content here was drawn from "C Programming, A Modern Approach" by K.N. King, Chapter 22.
Some material on this page was drawn from linuxmanpages.com and the C Reference section of cppreference.com
The following topics were covered in Formatted I/O
- printf
- scanf
The following topics were covered in Basic Text File Inpt and Output
- Binary versus Text I/O
- FILE * data type
- Standard FILE *s stdin, stdout, stderr
- fopen
- fprintf
- fscanf
- fclose
The following topics were covered in Character Strings:
- sscanf
- sprintf
- puts
- gets
- fgets
FILE *s are pointers to objects of type FILE, which will make more sense to us after we have studied structs
double data[ 100 ]; FILE *infile = fopen( "input.dat", "r" ); if( fread( data, sizeof( double ), 100, infile ) != 100 ) { fprintf( stderr, "Error: fread failed!\n" ); exit( -1 ); }
File descriptors are basically ints, that refer to entries in a ( system ) table
double data[ 100 ]; int fd = open( "inputfile.dat", O_RDWR ) if( read( fd, data, 100 * sizeof( double ) ) != 100 * sizeof( double ) ) { fprintf( stderr, "Error: read failed!\n" ); exit( -1 ); }