Problems:
Let's say that there are 3 arrays sized 20bytes, 13 bytes and 40 bytes respectively, I need to truncate/read these arrays, 5 bytes one by one and continue to truncate/read another 5 bytes once the loop repeats. Below is the layout:
array no first loop second loop third loop.......
1 5 bytes 5 bytes 5 bytes.....
2 5 bytes 5 bytes 5 bytes.....
3 5 bytes 5 bytes 5 bytes.......
I had written a source code to do this task but the problem is that it still continues to read 5 bytes eventhough it is the end of the array.
In this case, the second array of course will reach the end of array first.
This will cause some funny result. How do we stop reading the second array but in other hand, continues to read until the end of other arrays.
I had tried to stop the array that will ends first but it repeats reading when the loop, loops again.
Please help!
code
#include <stdio.h>
#include <stdlib.h>
void main()
{
int a, b, c;
//Declare and initialised array of pointers.
char *array[3]={"My name is David",
"Hello world",
"cockroach is smelly"};
//Truncate the array
.
for(a=0; a<5; a+=5)
/*A loop that steps through the array of arrays 5 times until it reaches 20.*/
{
/*A loop that steps through the arrays.*/
for(b=0; b<3; b++)
{
/*A loop that steps through the array of arrays 5 times starting at the point 'a' i.e. the variable of the first loop.*/
for(c=a; c<(a+5); c++)
{
printf("%c\n", array[b][c]);
}
}
}
}