C language Open File function use method _c language

Source: Internet
Author: User

ANSI c requires that the file be opened with a function fopen and closed to fclose.

1. The calling method is usually:

Copy Code code as follows:

FILE *FP;
Fp=fopen (filename, open mode);


2. Parameter Description:

FileName: such as "Myfile.dat", "F:\data\myfile.dat" and so on;

Open mode:
"R" (Read Only) opens a text file for input
"W" (write-only) opens a text file for the output
"A" (append) adds data to the end of the file file
"RB" (Read only) opens a binary file for input
WB (write-only) opens a binary file for the output
"R+" (Read and write) opens a text file for reading and writing
"w+" (Read and write) to create a new text file for reading and writing
"A +" (read/write) opens a text file for reading and writing
"Rb+" (Read and write) opens a binary file for reading and writing
"Wb+" (Read and write) to create a new binary file for reading and writing
"Ab+" (Read and write) opens a binary file for reading and writing

3. Note:

(1) The file opened with "R" can not input data to it, and the file already exists, otherwise error;
(2) The file opened with the "W" method, you can only enter data into the file, and if the file you open does not exist, create a new file named after the specified name, or delete the file when you open it, and then create a new file;
(3) If the function fopen open the file error, fopen returns a null pointer value;
(4) When the program starts running, the system automatically opens 3 standard files: standard input (stdin), standard output (STDOUT), standard error Output (stderr). If you want to use an input-output terminal, you do not need to open it, you can use it directly, such as FPUTC (stdout, ' a '), and output character a to the screen.

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.