The basic course of C language (iii) input and output functions and control flow statements (12)

Source: Internet
Author: User
Tags modifiers rewind

The

4.feof () and Rewind () functions
are called in the form of:
int feof (FILE *stream);
int Rewind (FILE *stream); The
feof () function detects whether the file location indicator has reached the end of the file, or returns a value other than 0, or 0. This function is particularly useful for binary file operations, because the end of file flag EOF is also a legitimate binary number, simply checking the value of the read characters to determine whether the file is finished or not. If that is the case, it may cause the file to not end and is considered the end, so you must have the feof () function.
The following statement is a common method of determining whether a file is closed.
while (!feof (FP))
Fgetc (FP);
While is the circular statement, which is described below. The
Rewind () function is used to move the file position indicator to the starting point of the file, returning 0 when successful, otherwise, a non-0 value is returned.

1.2.2 Non-standard file functions
This type of function was first used for UNIX operating systems, the ANSI standard is undefined, but it is sometimes used, and the DOS 3.0 version supports these functions. Their header file is io.h.
I. Opening and closing of documents
1.open () function
The open () function opens the file, which is called in the following format:
int open (char *filename, int access);
This function indicates that the file named filename is opened as required by access, and the return value is a file descriptor, where access has two parts: basic mode and modifiers, both of which are connected in the form of "(or"). Modifiers can have multiple, but only one of the basic patterns. Access rules are shown in table 3-2.
Table 3-2 Access rules
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Basic schema meaning modifier meaning
────────────────────────────
O_rdonly read-only o_append file pointer point to end
Create a file when O_wronly write only o_creat files do not exist
Property by Basic Mode property
O_RDWR Read-write O_trunc If a file exists, its length
Indent 0, properties unchanged
O_binary Open a binary file
O_text Open a text file
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The open () function is successful, and the return value is the value of the file descriptor (non-negative), otherwise 1 is returned.

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.