Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does fgets() move the file pointer ?

Tags:

c

file

pointers

Does the fgets() function move the file pointer automatically to the position till the parameter of the size mentioned by me ?

for example :

the content of the file p.txt is " I am a good boy " . After using fgets(a,5,fp1) does the file pointer move 5 positions ahead ?

Could not find this clearly in any book . Hence the query .

like image 803
Arka Prava Paul Avatar asked May 05 '17 16:05

Arka Prava Paul


2 Answers

after using fgets(a,5,fp1) does the file pointer move 5 positions ahead ?

The pointer fp1 is not affected by the fgets call (or any other stdio I/O routine); The FILE object that fp1 points to will be updated to reflect the new file position, but the pointer itself does not change.

like image 126
John Bode Avatar answered Nov 15 '22 05:11

John Bode


The file pointer is not modified by the fgets function.

However, the file offset is incremented by the number of bytes actually read.

like image 41
rtur Avatar answered Nov 15 '22 05:11

rtur