First, the problem description
Writes multiple records to a file, with each record occupying one row. Each record is written to calculate the size ( in bytes ) and number of records of all records in the current file, and write to the first line of the file ( that is, the file header ). For ease of differentiation, the size of the file record and the number of record bars in the file account for ten bytes, left-justified, insufficient bits to fill with spaces.
Second, the algorithm flow
Third,C code implementation
Iv. Description of the procedure
(1) This program is compiled with makefile file in Linux environment, the contents ofmakefile file are as follows:
Writefileheader:writefileheader.c
Gcc-c-G writefileheader.c
Gcc-g-O release/writefileheader writefileheader.o
RM *.O
(2) This program uses a number of file processing functions, such as:fopen,fputs,fflush,fclose,fseek, fread,fwrite and so on. Readers can thus experience the use of different file handling functions.
(3) This program demonstrates three times the file record of the writing process, you can according to their own needs of different records to test the program.
V. Results of program operation
After compiling the program with the makefile file, go to the release directory and execute the "writefileheader" command with the following results:
Writetofile:now Write header to file, Count of Content=1
Writetofile:now update file header, Count of content=2
Writetofile:now update file header, Count of content=3
View the TestFile.txt file with the following content:
The algorithm flow and C code implementation of the writing file header