Algorithm flow and C code implementation of writing file header

Source: Internet
Author: User

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

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.