Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C open file multiple times

Tags:

c

fopen

I have a file opened with fopen. There is a way to reopen the same file (while it is opened) but have a different seek? (so i can use fread independently)

like image 212
polslinux Avatar asked Mar 25 '13 17:03

polslinux


1 Answers

there is no problem if you keep reading only.

Be careful if you write in the file especially if you have 2 threads that access with read/write to the file at the same time

If your code looks like that

FILE *fp1, *fp2;

fp1 = fopen("file", "r");
fp2 = fopen("file", "r");

then you have 2 seeks in the same file. and the position of seeks are independent. reading from fp1 does not have any impact in fp2

like image 79
MOHAMED Avatar answered Sep 30 '22 03:09

MOHAMED