Hi,
I am trying to write a 1 GB file in blocks of 100KB and read them back in 100KB blocks. How do I get the pointer set to the correct value to read the next block? Could anyone please help?
Thank you!
Hi,
I am trying to write a 1 GB file in blocks of 100KB and read them back in 100KB blocks. How do I get the pointer set to the correct value to read the next block? Could anyone please help?
Thank you!
Are you doing all the reading consecutively? (As in, you're not trying to write to the file and then read from the same file and then write to the same file and then read from the same file etc.) If so, then there's nothing for you to do, as the file pointer is going to stay where you left it from the last time you read from the file.
If you mean fseek and ftell, then read a manual.
My favorite online reference:
long ftell(FILE *stream);
int fseek(FILE *stream, long offset, int whence);
Hi tabstop,
I am trying to do it randomly. I mean..not consecutive blocks. but then i should read the whole 1 GB file.
Thanks!
Tabstop:
Also, for doing it consecutively, how to write whole 1 gb file in chunks of 100kb first and trying to read it in 100kb chunks again???
Last edited by ccoolgoose; 06-01-2009 at 07:21 PM.
If you're reading randomly, then I guess fseek is what you're looking for. As to writing the file, just fwrite and fread and you're done. (I mean, I assume you have a 100K buffer, and you just write the buffer, replace it with the next block, write it, ad libitum.)
thanks!
For writing and then reading randomly...if i use fseek..how do i get to read all the blocks tandomly summing upto 1gb. could you please post an example
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Thanks...I think i want to write the whole file but not in consecutive blocks.
You might not have a choice about that; if you're writing the file from scratch you can't leave gaps. (If you're updating an existing file then you can update the records in place.) (Edit: Or at least I don't think you can, anyway; if it is possible I suppose someone will be along shortly.)
Yep..you are right! lets see