Please enable JavaScript.
Coggle requires JavaScript to display documents.
File I/O in C - Coggle Diagram
File I/O in C
What is File I/O
When we edit (read/write/change) the content of a file using C code, it is called file I/O in C.
Why files are needed?
When a program is terminated, the entire data is lost. Storing in a file will preserve your data even if the program terminates.
If you have to enter a large number of data, it will take a lot of time to enter them all. However, if you have a file containing all the data, you can easily access the contents of the file using a few commands in C.
-
Opening a file
Opening a file is performed using the fopen() function defined in the stdio.h header file.
The syntax for opening a file in standard I/O is:
ptr = fopen("fileopen","mode");
For example,
fopen("E:\cprogram\newprogram.txt","w");
Closing a File
The file should be closed after reading/writing.
Closing a file is performed using the fclose() function.
syntax:
fclose(fptr);
Working with files
When working with files, you need to declare a pointer of type file. This declaration is needed for communication between the file and the program.
Syntax :
FILE *fptr;
-
-