Algorithm flow for writing file headers, C code implementation, and algorithm flow
I. Problem Description
Write multiple records into the file, and each record occupies one row. Each time a record is written, the size (precise to bytes) and number of records of all records in the current file are calculated and written to the first line (that is, the file header) of the file ). For easy differentiation, the size of the file record and the number of records in the file each occupy 10 bytes, left alignment, fill in spaces with insufficient bits.
Ii. algorithm flow
III. C code implementation
Iv. program description
(1) This program is compiled using makefile in Linux. The content of makefile is as follows:
WriteFileHeader: WriteFileHeader. c
Gcc-c-g WriteFileHeader. c
Gcc-g-o release/WriteFileHeader. o
Rm *. o
(2) This program uses multiple file processing functions, such as fopen, fputs, fflush, fclose, fseek, fread, and fwrite. Readers can use different file processing functions accordingly.
(3) This program demonstrates the write process of three file records. You can test the program with different records as needed.
5. program running result
After the program is compiled using the makefile file, go to the release directory and run the "WriteFileHeader" command. The result is as follows:
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
The content of the unzip testfile.txt file is as follows: