-
loops
hi, im having a few problems implementing a loop into my program that will do exactly what im after. Firstly my loop has to run over 16384 bytes. This is the maximum and minimum it will run for. The problem is I need to create a loop that will break the 16384 bytes down into sections but each section will not always be the same size. For example the first time i run through my loop i mite need to take the first 32 bytes and preform all my processing on those bytes. Then when i go through again i might need to do my processing on the next 96 bytes and so on. Basically I need to process my loop so that it runs through all 16384 bytes but each section i process may differ in size (multiples of 32). Basically im parsing through the directory structure of a FAT image and Long files names are causing the difference in the section size of my loop. Ive been racking my brains on how to do this and I think the loop is going to be the best way but is it possible to create a loop that changes its chunk size depending on what i want (if that makes sense)?
thanks
-
Code:
int pos=0;
int stop = 16384;
while(pos<stop)
{
void *block;
unsigned int blockSize = getNextBlock(block,pos);
processBlock(block,blockSize);
pos+=blockSize;
}
-
Something like
Code:
for ( i = 0 ; i < 0x4000 ; i += amount ) {
// various things which update amount depending on what is found
}
-
brill this looks like the sort of thing I was after! Can i just check i know how this works first to make sure I just dont jump into things head first. I'm not toally sure what is occuring inside the loop and how its happening but I think i know whats going on just not how its doing it.
One thing is that the first byte of each block tells me how much the block size has to be, so for example i read the first byte, i work out that corresponds to 96 then i need to pass the 96 back to my loop somehow to say, i need 96 bytes and move my next chunk to start at the 97 byte to start the process all over again
Code:
int pos=0; //increments everytime it is passed a new block size
int stop = 16384; //max of my loop
while(pos<stop)
{
void *block; //not sure what this does
unsigned int blockSize = getNextBlock(block,pos); //not sure what this does
processBlock(block,blockSize); //not sure what this does
pos+=blockSize; //Adding the block size to variable pos to increment its value?
}
thanks
-
that will not completely do everything you need.
block is a pointer to a location within whatever object your are processing that has these variably sized blocks of information, or sections, as you were calling it. getNextBlock would be some function that finds the start of the next block/section from the location pos, sets block to point to that location, and returns the size of the block/section. it might be convenient to implement it as either whateverObjectYourProcessing::getNextBlock or getNextBlock(object,block,pos). i don't have enough background info to tell exactly which makes the best sense for you.
process block would be a function that does whatever you're trying to do with these pieces of information.
yes, incrementing pos by blocksize will make sure you stop when you hit 16384.
so, i don't know what those functions do either because i don't know what you're doing. this is just a possible loop structure that might accomplish what you're after.