File Processing
File Processing
Buffer area
is part of the memory used as a tempoarary space before data moved to a file.
Syntax :
File *fp
where fp is a file pointer pointing to the start of the buffer area.
File *fp
where fp is a file pointer pointing to the start of the buffer area.
Open File
Opening a
File using fopen()
fp=fopen(const char *filename, const char *mode);
Possible Mode value:
“r” : opening a file to be read.
“w” : creating a file to be written.
“a” : opening a file for data append.
“r+” : opening a file for read/write.
“w+” : creating file for read/write
“a+” : opening a file for read/append.
“rb” : opening a file (binary) to be read.
“wb” : creating a file(binary for write operation.
fp=fopen(const char *filename, const char *mode);
Possible Mode value:
“r” : opening a file to be read.
“w” : creating a file to be written.
“a” : opening a file for data append.
“r+” : opening a file for read/write.
“w+” : creating file for read/write
“a+” : opening a file for read/append.
“rb” : opening a file (binary) to be read.
“wb” : creating a file(binary for write operation.
Close file
Closing a file using fclose():
int fclose(File *stream);
Closing a file using fclose():
int fclose(File *stream);
Input &
Output File
1.
Fwrite
-
Syntax :
size_t fwrite(const void *buffer, size_t size, size_t count, FILE *stream);
-
Writing a
block of data in the buffer area to the file
-
Return number
of byte data written, and error otherwise.
2.
Fread
-
Syntax :
size_t fread( void * buffer, size_t size, size_t count, File *stream);
-
Read a
block size of data from a file
3.
Fscanf
-
Syntax :
int fscanf(File * stream, const char *format[,argument]…);
-
Read data from
file inline with the scanf formatting.
-
Return the
number of field read while successful, and EOF if error
4.
Fprintf
-
Syntax : int
fprintf(File *stream, const char*format[,argument]…);
-
Writing data
to a file using the printf format.
-
Return number
of byte written if successful and negative value if error.
download here
https://drive.google.com/drive/folders/1kX5HzH239kVsDjqspL-d0FsqiqL8rvJR?usp=sharing
https://drive.google.com/drive/folders/1kX5HzH239kVsDjqspL-d0FsqiqL8rvJR?usp=sharing
Komentar
Posting Komentar