C Language Application Operation files

Source: Internet
Author: User

File is the C language in Germany, the focus of the small part in the basic knowledge of C language, most of the input and output operation is on the screen, and now finally in the document learning to feel the tall on the sample paper. In the previous data volume is very small, we usually use the information from the keyboard on the screen for input and output, but when the amount of data is very large, it is very cumbersome, so we will need to use the file (files).

This post mainly involves the knowledge point has:

    • File read operation;
    • File write operation;
    • file pointers;
    • The positioning of documents;
    • Buffered file systems and non-buffered file systems.

I. Introduction to Documents (file)

In C, a file is made up of a single character, and the content in the file is called a file stream.

Files can be divided into two types: ASCII files and binary files.

    • ASCII files are characters that store information and are readable;
    • Binary files are stored in binary form, that is, using a series of binary numbers to represent, suitable for non-character-based data. If you open it in Notepad, you will see only a bunch of garbled characters. Therefore, in addition to the text file, all data can be considered binary files. The advantages of binary files are fast access, small footprint, and random access to data.

  

According to the file processing method, the file can be divided into: buffer files and non-buffered files two kinds. However, the buffer file is used in the standard C language.

The first step is to understand the buffer: the extra memory that is provided when the program executes, which can be used to temporarily hold the data ready for execution. Its role is to implement the file as a mediator related operations, in order to improve access efficiency, because the memory access speed is much faster than the disk drive.

Buffered files: When a read operation is performed on a file, a portion of the data is read from the file into the buffer and the files in the buffer are read into the corresponding variables. When a file is written, the data is written to the data buffer, and if the buffer storage space is full, then the contents of the buffer are written to the file. In short, the file in the buffer where the data resides is the buffer file.

Buffer file implementation of the file read and write operations are implemented by pointers.

The file is defined in the following form:

       FILE * pointer name;

Use pointers to manipulate files.

  

  

  

C Language Application Operation files

Related Article

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.