Next: sprintf and sscanf Up: Files Previous: Files

Reading and writing FILES

The functions fprintf and fscanf a commonly used to access files.

These are similar to printf and scanf except that data is read from the stream that must have been opened with fopen().

The stream pointer is automatically incremented with ALL file read/write functions. We do not have to worry about doing this.

Other functions for files:

int getc(FILE *stream), int fgetc(FILE *stream)

int putc(char ch, FILE *s), int fputc(char ch, FILE *s)

These are like getchar, putchar.

getc is defined as preprocessor MACRO in stdio.h. fgetc is a C library function. Both achieve the same result!!

fflush(FILE *stream) - flushes a stream.

fclose(FILE *stream) - closes a stream.

We can access predefined streams with fprintf etc.

fprintf(stderr,``Cannot Compute!!n'');

fscanf(stdin,``%s'',string);


Dave.Marshall@cm.cf.ac.uk
Wed Sep 14 10:06:31 BST 1994