C Primer Plus 13th Chapter Study Summary ... 2015.5.8

Source: Internet
Author: User
Tags fread

Chapter 13th: Input/output of documents


This chapter is very confusing to learn, and the above chapters are not too coherent, introducing a lot of
Functions for file input and output, just like high school math, suddenly appeared a lot
Formulas, although each formula knows what to do, how to use, but it is not necessarily the problem
Made it out. After reading this chapter, I just have a general understanding of the various output input of the file, playing
Open and so on. Therefore, further understanding and practical application are needed.


< redirect operator, echo_eof<words the operator to words file with the
The stdin stream is associated to boot the file words content into the echo_eof program.

echo_eof send keyboard input to a file named Mywords


Echo_eof>mywords
The redirect operator connects an executable program to a data file to establish
New file.

File view: Stylistic view binary view

Standard I/O two advantages: 1, it contains a lot of special functions 2, the input and output of the cache

The exit () function closes all open files and terminates the program, normally terminating the normal return
0, non-normal return non-zero.

Recursive in exit () will still terminate the program. Return simply terminates this level of the program and
Control over to the previous level.

fopen () to open the file. The first parameter is the file name that the file pointer points to, and the second
The parameter is the open mode FILE*FP; fopen (FP, "R"), successful return pointer, missing
Failed to return null.
Fclose () Close file, fclose (FP), successful return 0, failure returns NULL.

Getc () function, PUTC () function

Ch=getchar (); Gets a character from the standard input.

GETC (CH,FP); Gets a character from the file pointed to by the pointer
PUTC (CH,FP); writes a character to a file pointed to by the pointer


The fprintf () fscanf () function is just as many parameters as printf scanf
is to input and output the file the first parameter is a file pointer


The Fgets () function (obtains a string from a file) three parameters, the first parameter stores the output
Enter address the second parameter integer, the maximum length of the string, and the third parameter file pointer
, point to the file you want to read

Fputs () (Put a string into a file) two parameters, first parameter output string
Address, the second parameter file pointer, writes a string to the specified file


Random Access
Fseek () (Navigate to the file in that position) three parameters: the first parameter file refers to a
The needle points to the file being searched; The second argument: The offset indicates that you want to move from the starting point
The distance Long data type is positive forward negative back shift 0 hold still; the third parameter
Is the starting point in which mode Seek_set Seek_cup the current position at the beginning of the file
End of Seek_end file. If everything returns 0 correctly, the error returns-1;


Ftell () parameter file pointer that returns long data by returning the word from the beginning of the file
The number of sections to determine the current position.


Fwrite () Double Enrnings[10];fwrite (enrnings,sizeof
(double), 10,FP); The data in the array is written to a file, and the data is divided into 10 blocks, each
Size Double

Fread () Double Enrnings[10];fread (enrnings,sizeof
(double), 10,FP); A 10 double value is called to copy into the array.































C Primer Plus 13th Chapter Study Summary ... 2015.5.8

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.