This is what I am looking to do.
I have this array where there's say 512 bytes (512 char arrray).
I need to extract 32 bytes from it and send it elsewhere. So basically I need a way to keep a track of 0-32 bytes, then move to 33-64 and so on.
I do know the length of the array or can get it from the first 32 bytes.
So here's my logic:
- Create a pointer (ptr) to point to start of the array that holds the data.
- Use a for loop
for( x=0;x<=511;x++0
- Inside use another for loop
for ( i=0;i<=31;i++)
In here I use a pointer to copy data to another 32 byte arrayx
arrayx[i]=*ptr++;
- if i = 32, then I send 32 bytes to the destination and x=i.
SO this would make x =32 and get into the outer for loop.
Now I need to copy from 33rd byte of the initial array to 64 and so on. But I am kinda getting stuck/confused at how to proceed.
WOuld anyome be able to suggest a better or kinda complete this logic ?
Thanks for all your help.
The range 0-32 is 33 bytes long, not 32.
Just use x+=32 as the increment, i<32 as the while condition, and access elements as array[x+i]. That's the second briefest method I can think of. The briefest method I can think of is using memcpy().
yea, dunt bother about the 32..33 stuff. Just wanted to run the logic by some people. Lemme also think about memcpy.
Somehow I don't use while loops often enough :)
Thanks anyways.
Um... No, I didn't tell you to use a while loop. That's what I call the condition for the for, since the loop will continue *while* the condition is true.
while (i<=max length) // say temp[150]
{
for (int x=0;x<=31;x++)
{
buffer_out[x+i] = temp[x+i]; // copy into buffer_out
}
if (x==32)
{
i=x; // i = 32 when loop exits
fpga_recv(); // call whatever function I need to.
}
} // while loop ends
}
SO now I can keep adding 32 bytes at a time, send it over to where ever I need to :)
If you find any issues with it lemme know.