Algorithm flow for writing file headers, C code implementation, and algorithm flow

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.