Hi,
Can I seek a file using 2 lseek() at the same time, each one seeks for different thing?
Hi,
Can I seek a file using 2 lseek() at the same time, each one seeks for different thing?
Nothing happens in a single process "at the same time". If they're separate processes then it makes no difference because each has its own internal offset pointer. You'll have to be more specific about what you're actually doing.
If you understand what you're doing, you're not learning anything.
No, you can't. The second lseek() will start where the first left off.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
You could always do something like this:
Code:#include <stdio.h> void showline(FILE *fp, long *offset) { char buf[BUFSIZ]; fseek(fp, *offset, SEEK_SET); fgets(buf, sizeof(buf), fp); fputs(buf, stdout); *offset = ftell(fp); } int main(void) { FILE *fp; long offsets[2]; int i; if(!(fp = fopen("flipflop.txt", "r"))) { puts("Unable to open 'flipflop.txt' for reading!"); return 1; } offsets[0] = 0; offsets[1] = 50; for(i = 0;i < 5;++i) { showline(fp, &offsets[0]); showline(fp, &offsets[1]); } fclose(fp); return 0; }Code:itsme@itsme:~/C$ cat flipflop.txt 000000000 111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999999 itsme@itsme:~/C$That's using standard streams, but the concept is the same for low-level I/O.Code:itsme@itsme:~/C$ ./flipflop 000000000 555555555 111111111 666666666 222222222 777777777 333333333 888888888 444444444 999999999 itsme@itsme:~/C$
If you understand what you're doing, you're not learning anything.