C Language File Operation function Daquan

Source: Internet
Author: User
Tags define function error code header string format

Clearerr (clear file stream error flag)

Correlation function feof

Table header file #include <stdio.h>

Defines the function void Clearerr (FILE * stream);

The function Description Clearerr () Clears the error flag used by the file stream specified by the parameter stream.

return value

Fclose (Close file)

Correlation function Close,fflush,fopen,setbuf

Table header file #include <stdio.h>

define function int fclose (FILE * stream);

The function Description fclose () is used to close the previously fopen () Open file. This action will cause the data in the buffer to be written to the file and release the file resources provided by the system.

The return value returns 0 if the closed file action succeeds, and returns EOF when an error occurs and saves the error code to errno.

The error code EBADF represents a file that is not open for the parameter stream.

Please refer to fopen () for examples.

Fdopen (converting file descriptors to file pointers)

Correlation function Fopen,open,fclose

Table header file #include <stdio.h>

Defines the function FILE * fdopen (int fildes,const char * mode);

The function Description Fdopen () Converts the file descriptor of the parameter fildes to the corresponding file pointer and returns. The argument mode string represents the flow pattern of the file pointer, which must be the same as the original file description Word read and write mode. Refer to fopen () for the mode string format.

Returns a file pointer to the stream when the return value conversion succeeds. Failure returns null and the error code exists in errno.

Example

#include<stdio.h>
main()
{
FILE * fp =fdopen(0,”w+”);
fprintf(fp,”%s\n”,”hello!”);
fclose(fp);
}

Execute hello!

Feof (check that the file stream is read to the end of the file)

Correlation function Fopen,fgetc,fgets,fread

Table header file #include <stdio.h>

define function int feof (FILE * stream);

Function Description feof () is used to detect whether the end of the file is read, and the mantissa stream is the file pointer returned by fopen (). Returns a value other than 0 if it is at the end of the file, and returns 0.

The return value returns a value other than 0 that represents the end of the file that has reached.

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.