The so-called "file" refers to an ordered set of related data. This dataset has a name, called the file name. In fact, in the previous chapters we have used the files many times, such as source program file, target file, executable file, library file (header file ) and so on. files usually reside on external media , such as disks , and are only transferred into memory when they are used.
Example one: Reading the contents of a file
#include <stdio.h>intMain () {FILE*FP; Charch; if((Fp=fopen ("D:\\c1.txt","RT"))==NULL) {printf ("\ncannot Open File strike any key exit!"); Getch (); Exit (1); } CH=fgetc (FP); while(ch!=eof)//Ch is a character, one of them is taken out{putchar (ch); CH=FGETC (FP);//reads a character from the file pointed to by the file pointer stream, reads a byte, and then moves the cursor position one byte after the other. } fclose (FP);}
Operation of files in C language