There are two tyoes of files.
There are different operations that can be carried out on a file. These are:
Function | Description |
---|---|
fopen() | create a new file or open a existing file |
fclose() | closes a file |
getc() | reads a character from a file |
putc() | writes a character to a file |
fscanf() | reads a set of data from a file |
fprintf() | writes a set of data to a file |
getw() | reads a integer from a file |
putw() | writes a integer to a file |
fseek() | set the position to desire point |
ftell() | gives current position in the file |
rewind() | set the position to the begining point |
feof() | Detects the end of file. |
ftell() | Returns the current pointer position. |
rename() | Changes the name of file. |
The syntax for opening file in standard I/O is:
FILE * ptr; ptr = fopen("file_name","mode")
Function | Description |
---|---|
r | opens a text file in reading mode |
w | opens or create a text file in writing mode. |
a | opens a text file in append mode |
r+ | opens a text file in both reading and writing mode |
w+ | opens a text file in both reading and writing mode |
a+ | opens a text file in both reading and writing mode |
rb | opens a binary file in reading mode |
wb | opens or create a binary file in writing mode |
ab | opens a binary file in append mode |
rb+ | opens a binary file in both reading and writing mode |
wb+ | opens a binary file in both reading and writing mode |
ab+ | opens a binary file in both reading and writing mode |
int fclose(FILE*fp);
The fclose() returns zero on success, or EOF if there is an error in closing the file.