i write a strtok program, i think should be got some errors but i cant figure it out why.Can anyone please tell me what is the problem of my program? Thanks for helping.
My program need to convert the string into 1-dimesion array, but it fails.
Code:
int main(void){
char words[20][20] = {"we are happy.", "happy,", ",friday." };
int i, j;
char delim[] = ",.";
char *result;
for ( i=0; i<20; i++){
for( j=0; j<20; j++){
result = strtok( &words[i][j], delim);
while( result != NULL){
printf("%s\n", result);
result = strtok(NULL, delim);
}
}
}
}
My Output Supposed to be :
we
are
happy
happy
friday
But after compile my program above, my output is:
we
are
happy
we
e
are
re
e
happy
appy
ppy
py
y
happy
appy
ppy
py
y
friday
riday
iday
day
ay
y
what is the program error ar? i cant figure it why@