#include <stdio.h>
#include <string.h>
int main()
{
unsigned int a, b, c, wh;
char *array[3]={ "smelly",
"Hello world",
"piece of cake hellol asdjfksd asdfsf adsfa sfaafa"};
printf("Please enter the array that you wish to truncate");
scanf("%d", &wh);
for(a=0; a<50; a+=5)
{
for(b=0; b<wh; b++)
{
for(c=a; c<(a+5); c++)
{
if ( c < strlen(array[b]) )
printf( "%c", array[b][c] );
}
printf( "\n" );
}
printf( "-----\n" );
}
return 0;
}
If I assign number '3' to the address of variable 'wh', the loops
truncate the array just fine. The problem is when I
assign the number '1' to the address of variable 'wh', the loops truncate
as usual but I found out that this is not efficient because the outer loop
still loops until it reaches 50 bytes, while the first array just contains 6 bytes!
How do I stop the outer loop loops when it is end of the first array?
I had tried many ways to solve this but to no avail.
Please help!