fgetc()
Reads an character from the file and store it in a char variable. If the first time use this function, the file pointer will start from the beginning of the file. After that, will start from the next character from the previous position.
* The related file pointer must be opened as "r" for reading, if not you will suffer an error.
char ch = fgetc(<file pointer>);
char ch = fgetc(ptr1); // read a character from the file pointer "ptr1" and store it into char variable "ch".
One way of practical use of fgetc():
The ability to get single characters from files, if wrapped in a loop, means we could read all the characters from a file and print them to the screen, one by one, essentially.
char ch;
while ((ch = fgetc(ptr)) != EOF)
printf("%c", ch);
So in this line of code, will first read a char from the file and store it into variable "ch". Compare this "ch" with "EOF" to make sure it's not the end of the file. And print this char onto the screen using "printf()".
There is a Linux command "cat" that does this. If you type "cat filename" it will print out whole content of the file in your terminal window.