There are some operations that can be done by a user regarding files.
In order to work with a file, we need to declare pointer of a type file which is used for communication between file and program.
FILE*fptrIn C-programming, File can be opened by an inbuilt function fopen() available in stdio.h library.
Syntax for opening file:
FILE*fptr=fopen("fileName","mode")It contains two literals, filename is a string literal which refers to the name of a file to be open along with it's extension also if file is stored in any other directory, user have to specify that path. Mode contains many options. Some option are right below:
| File Mode | |
|---|---|
| r | |
| rb | |
| w | |
| wb | |
| a | |
| ab | |
| r+ | |
| rb+ |
These are few modes which can be used in file processing.
Example:
fptr=fopen("C:\TURBOC3\program.txt","w");For closing anything, we need first to use it or complete it. The same is the case with file, it should be closed after using or working on it.
Like opening a file, it can be closed by a similar function fclose() available in library.
Syntax for closing file:
fclose(file_pointer); fclose(fptr)STAY TUNED FOR NEXT TOPIC.
| UPVOTE | COMMENT | RESTEEM |
|---|---|---|
| IF YOU | LIKED | MY POST |