File Operations
1. File path
absolute path from the root directory such as C beginning of the disk: \ Program Files \ Microsoft Office \ Office14
can omit the relative path ./123.txt ./ current directory in the project folder ../ representation level directory / directories to the divided multilayer
Relative path commonly used represents a string \\ \ escape character
Binary files are stored with the way computers are binary file mp3 wav word file
with txt 's contents are not garbled if the code is a binary file
without the txt file is garbled
text Notepad to open the file will not be garbled txt .c .cpp
2. The file pointer and file manipulation functions
FILE * fp; // define pointer file
1. open and close files fopen fclose
2. The file read and write functions
text file is read each time a single character content fputc fgetc
fgetc reads one character from the document
fputc written to a file to which a character
mode to read and write the string fgets fputs
fscanf fprintf formatting reading
fread fwrite
generally not simultaneously read and write files
f function means a function
fgetc get char resulting file is read and a character
meaning fputc put char place to write the file
s string string
printf output to an external write file fprintf
scanf read fscanf fetch data file read
read read fread to read the file
write fwrite write file
123456 character type digital text file -> stored in the text which indicates that the 6 characters numeric string
(no distortion, but not strong confidentiality)
internal binary computer store integer int embodiment 123456 4 bytes
(read when the distortion will be faster but for programs)
other function
fseek move the file pointer
ftell calculated internal file pointer offset (offset relative to the beginning of the file)
feof
rewind the file pointer is moved back to the beginning of the file
After fp (internal file pointer) points to always open the file fp file
but a file pointer to the current read internal position
if the internal pointer r is opened at the beginning of
w / a document at the end of
the fopen ( "relative path" Open "file ");
Open three RWA
R & lt Read Read Read data will fail if the open file does not exist from the file
w write write write empty file if the file does not exist then it will create a new file
a append the source file is added behind the increase in new content file creates a new file does not exist
Modifications can be added later or b indicates binary t tb text files (commonly abbreviated t)
rb open reading binary manner will open if the file does not exist fail
rt open the text file to read (t may be omitted)
+ + indicates if followed by a read-write file
rb + open reading binary manner can read and write files
rb + b + represents a binary file read and write
r reads a file does not exist, if the open failure open
EOF end of file end of file
fopen------->fopens
fopen_s (& fp, the file path, the file open mode);