Read data from file

fscanf() function is used to read data from file.

Syntax of fscanf() :

Code example:

Here first we open test.txt in writing mode and write “KUET EEE” text. Then retrieve first word “KUET” by

Here s[20] can contain 19 character but why only “KUET” is retrieved by

Here retrieving data has been terminated by space. Notice there is space between “KUET” and “EEE”.

So, How to read all data including space? is a big question.
We can do this by feof() function.

feof() function will return non-zero value for any position of file except end of the file and zero value for the end position of file. File position is updated by file pointer fp.