File Processing
Processing a file in C is surprisingly easy all you have to do is declare a file
FILE *fileVar
like so.
whenever you want to open a file all you have to do is
fileVar = fopen("fileName.ext","mode");
there are many types of mode:
don't forget to close your file with
fclose(fileVar);
FILE *fileVar
like so.
whenever you want to open a file all you have to do is
fileVar = fopen("fileName.ext","mode");
there are many types of mode:
r | Open for reading. | If the file does not exist, fopen() returns NULL. |
rb | Open for reading in binary mode. | If the file does not exist, fopen() returns NULL. |
w | Open for writing. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
wb | Open for writing in binary mode. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
a | Open for append. i.e, Data is added to end of file. | If the file does not exists, it will be created. |
ab | Open for append in binary mode. i.e, Data is added to end of file. | If the file does not exists, it will be created. |
r+ | Open for both reading and writing. | If the file does not exist, fopen() returns NULL. |
rb+ | Open for both reading and writing in binary mode. | If the file does not exist, fopen() returns NULL. |
w+ | Open for both reading and writing. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
wb+ | Open for both reading and writing in binary mode. | If the file exists, its contents are overwritten. If the file does not exist, it will be created. |
a+ | Open for both reading and appending. | If the file does not exists, it will be created. |
ab+ | Open for both reading and appending in binary mode. | If the file does not exists, it will be created. |
don't forget to close your file with
fclose(fileVar);
Comments
Post a Comment