Before reading that file using the program, create a text file in the current directory and add some text to the file using a simple manual.
Follow the steps to read the file:
To read any file, you must open a text file using the file cursor.
fpReadFile = fopen ("sampleFile.txt", "r");
Launch the loop until it reaches EOF (end of file). Now read each letter in the file using the getc ()
function.
while ((c = getc (fpReadFile))! = EOF)
putchar (c);
When the reading is complete, close the file.
fclose (fpReadFile);
Note: If you do not have a text file to read, fopen () will return NULL.
File description step description:
As steps for reading a file, create a file cursor.
File * fpWriteFile;
Open File. Here you have to open the file by typing "w" mode.
fpWriteFile = fopen ("sampleFile.txt", "w");
Write the text in a file.
fprintf (fpWriteFile, "\ nEditing is a masterpiece.");
Close the file.
fclose (fpWriteFile);
Here is the program in C to write the file.
|