If you’re going to use C strings, you need to add a null terminator at the end of each string
do {
b[I][k]=a[j];
k++;
} while(j+k<strlen(a) && a[j+k]!=' ');
b[I][k] = '\0';
As ppeterka noted, you also need to change your loop exit condition to avoid an infinite loop.
Note also that the repeated calls to strlen
here and in your code are wasteful. You should consider calculating this once before your for
loop instead.
solved Whats wrong with the following code [closed]