Linux parse file functions

Source: Internet
Author: User

# Include <stdio. h>

FILE * fopen (const char * path, const char * mode );
Int fclose (FILE * fp );

If you want to parse the content of a file, you must first open the file.
You can choose to enable read-only, write-only, or read/write based on your specific needs.

# Include <stdio. h>

Int fgetc (FILE * stream );
Char * fgets (char * s, int size, FILE * stream );

After the file is opened, you can use functions such as fgetc/fgets to read the content of the file.
Fgetc is used to read a character from the position pointed by the file pointer fp each time;
The fgets function reads size characters from the position pointed to by the file pointer fp until the end of a line break occurs;
If the end of a file is EOF, it means the end of the file.

# Include <stdio. h>

Int fclose (FILE * fp );

After the File parse is completed, remember to use fclose to close the open data stream.
The fclose function has the following functions:
1. If the file content is modified, write the data in the buffer back to the disk. Note that it is a disk.
If it is a temporary file created from the memory, there is no flush.
Only after the file is written back to the disk, the buffer opened in the fopen file will be recycled by the system.
For flush, refer to the following article,
2. Disable opened file descriptors.

Note: The above are all standard I/O 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.