C language files and their related functions

Source: Internet
Author: User
Tags fread rewind

A file is a basic way of storing data in a computer system. It is a collection of data that is stored in an external storage device and named.

The data is stored as a file on the external media, and the operating system manages the data in the form of files.


Files can be divided into data files and program files according to the contents of storage:

Data files:

Program Files: source program manifest or compiled connected executable file (also in broad sense is data file)


Disk file name: path \ filename. extension


Disk files can be divided into binary files and text (data stored in ASCII format) files in the format of storage

12345 is two bytes for shaping, 5 bytes for character, text file even with character type (ASCII)


File-type pointers

A file type is a special "structure" in which the members of the structure record the information that is required to process the file: The file symbol, the number of bytes remaining in the buffer, the file operation mode, the address of the next byte to be processed, and the first address of the buffer.


FILE-type pointers:

The C language defines this structure in stdio.h, whose type is file, which the user can use to define a file-type pointer variable, defined as follows:

File * Document type pointer name 1, file type pointer name 2, ...;


Opening and closing functions of a file

Common functions:

fopen

Fclose: Returns 0 if properly closed

Feof

FPUTC: Write character functions, primarily for text files, or for processing binaries.

FGETC: read character function;

Fputs: Reading a string function; int fputs (char *str, FILE *FP)

Fwrite: Write data function; int fwrite (char *buf, unsigned int size, unsigned int n, FILE *fp)

Fread: Read data function: int fread (char *buf,.... Parameter with write data function)

Rewind: header locator function; int rewind (file *fp)

Fseed: File random location function;



C language files and their related functions

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.