Something along the lines of the following - note that there are some parts left out to fill in int write_count = 0; int file_idx = 1; FILE *fp; char filename20; sprintf( filename, "codes%d", file_idx ); file_idx++; fp = fopen(filename, "wb"); while( foo ) { //update data if( write_count + sizeof(keyEncode) > ONE_GIGABYTE ) { fclose(fp); write_count = 0; sprintf( filename, "codes%d", file_idx ); file_idx++; fp = fopen(filename, "wb"); } fwrite(storedVal, sizeof(keyEncode),1,fp); write_count += sizeof(keyEncode); } fclose(fp) Update You could incorporate logic like this into a helper function to write, as per Aaron's response. Note that you would have to make some of the data members global and it would not be thread safe.
Something along the lines of the following - note that there are some parts left out to fill in. Int write_count = 0; int file_idx = 1; FILE *fp; char filename20; sprintf( filename, "codes%d", file_idx ); file_idx++; fp = fopen(filename, "wb"); while( foo ) { //update data if( write_count + sizeof(keyEncode) > ONE_GIGABYTE ) { fclose(fp); write_count = 0; sprintf( filename, "codes%d", file_idx ); file_idx++; fp = fopen(filename, "wb"); } fwrite(storedVal, sizeof(keyEncode),1,fp); write_count += sizeof(keyEncode); } fclose(fp); Update You could incorporate logic like this into a helper function to write, as per Aaron's response. Note that you would have to make some of the data members global and it would not be thread safe.
I almost want to -1 for ONE_GIGABYTE. MAX_SIZE_PER_FILE would be reasonable, but avoiding magic numbers by writing the name of the number as a string is just about the most idiotic programming dogma I can think of. Would you write int x = FOURTY_TWO;?
– R.. Nov 16 '10 at 16:26 is int fp , meant to to be File *fp? If not what is it – molleman Nov 16 '10 at 16:30 @R "note that there are some parts left out to fill in" - I'm not here to name his variables or constants, I just want it to be clear for the question asker what values should go where. Also a gigabyte is a number with a unit not just a number – Gavin H Nov 16 '10 at 16:32 @molleman - correct, I updated the answer – Gavin H Nov 16 '10 at 16:39.
Create a set of little helper functions which work the same as fopen()/fwrite() but work on their own data structure instead of on FILE*. That allows you to save the file name in your structure, close the real file and open a new one when your implementation of fwrite() notices that enough data has been written. If you want to take this over the edge, use a couple of macros to overwrite the original methods: #define fopen my_fopen They must not be used for your helper functions, of course.
But it allows you to compile the old code and "magically" change its behavior.
How do I get it to notice 1 gb is written – molleman Nov 16 '10 at 15:52.
I want to write the data out into 1gb files. How would I got about doing this? At the moment, I go through a while loop (with a condition that will go on until 5 gbs data is created).
I would like each file to be called codes1, codes2 and increment on until the while loop is finished. I am sure it would include an if statement based on the size of the current file it is writing to. Then when it reaches 1gb, it begins on a new file.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.