GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Jan-2008, 17:50
tootypegs tootypegs is offline
Junior Member
 
Join Date: Nov 2007
Posts: 32
tootypegs has a little shameless behaviour in the past

Loops


Hi im having a problem creating some loops in my program.

Basically i was trying to impliment a loop that runs until 16384 bytes have been captured. I then want to run a loop inside this one that cuts the 16384 bytes into 32 byte chunks starting at the first byte and cutting it into chunks from there. I have had a go at this but i cnt seem to get anything to work,
can anyone help me to correctly impliment this? thanks

Code:
char iobuf[32]; //hold the 32 byte chunk f.seekg (START_OF_ROOT,std::ios::beg) ; // Positions at start of the 16384 bytes for(i= 0; i < 16348; i++) { while( iobuf<=sizeof(iobuf)) { f.read (&iobuf,sizeof (iobuf)) ; } }
  #2  
Old 04-Jan-2008, 07:22
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Loops


It sounds to me like you want to store your bytes into an array like:
CPP / C++ / C Code:
unsigned char data[512][32];
Then, you can have two loops like this:
CPP / C++ / C Code:
int i,j;
for(i=0;i<512;++i)
{ for(j=0;j<32;j++)
  { // read a byte into data[i][j]
  }
}
Is this the solution you were looking for or am I misunderstanding you?
  #3  
Old 04-Jan-2008, 08:49
tootypegs tootypegs is offline
Junior Member
 
Join Date: Nov 2007
Posts: 32
tootypegs has a little shameless behaviour in the past

Re: Loops


Yer overal i have for example 512 bytes. I need to loop through the 512 bytes starting at byte 1. I need to capture a block of 32 bytes. With that 32 bytes i need to look at the structure and do some calculations. Once im done with that 32 bytes i would then need to move to the next 32 which will be bytes 33-64 and produce the same calculations. This would have to be done until i finally example all chunks in the 512 bytes
  #4  
Old 04-Jan-2008, 09:25
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Loops


OK. How about this:

CPP / C++ / C Code:
int i,j;
char iobuff[32];
for(i=0;i<512;++i)
{ for(j=0;j<32;++j)
  { // read a byte into iobuff[j]
  }
  
  // Process iobuff[] here
}
  #5  
Old 04-Jan-2008, 11:10
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,620
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Loops


Quote:
Originally Posted by fakepoo
OK. How about this:
CPP / C++ / C Code:
for(i=0;i<512;++i)
{ for(j=0;j<32;++j)
  { // read a byte into iobuff[j]

Doesn't your code attempt to read 16384 bytes? (512*32 = 16384)

Shouldn't the outer loop limit be 16? (16*32 = 512)

Regards,

Dave
  #6  
Old 04-Jan-2008, 12:24
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Loops


Quote:
Originally Posted by davekw7x
Doesn't your code attempt to read 16384 bytes? (512*32 = 16384)

Shouldn't the outer loop limit be 16? (16*32 = 512)

Regards,

Dave
Good point. The first post says 16384 and the other one says 512. I don't know.
  #7  
Old 04-Jan-2008, 14:11
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,620
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Loops


Quote:
Originally Posted by fakepoo
Good point. The first post says 16384 and the other one says 512. I don't know.

Upon reflection, I am thinking your code is in keeping with the assignment. Sorry to muddy the waters.

Regards,

Dave
 

Recent GIDBlogPrepping for deployment by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What exactly are real world examples that utilize structured loops? lynlawdac CPP / C++ Forum 2 13-Nov-2007 09:06
Having Problems with Loops cristale10 CPP / C++ Forum 2 02-Oct-2006 14:58
nested for loops sandeepeecs C Programming Language 3 20-Aug-2006 08:49
Help with nested for loops...please. sorry newbie keperry CPP / C++ Forum 14 16-Oct-2004 11:25
Help using nested for loops dontcare CPP / C++ Forum 1 03-Oct-2004 12:33

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.