please tell me why this code give me segmentation fault?
I want to split the command into tokens but I don't know why it give me segmentation fault!!
char command[500]="asdadas asdasdas asdadas";
int i,j,k;
char tokens[4][200];
for(i=0,j=0,k=0; i<strlen(command); i++)
{
if(command[i]==' ')
{
tokens[j][k]='\0';
k=0;
j++;
continue;
}
tokens[j][k]=command[i];
k++;
}
tokens[j][k]='\0';
strtok's whole purpose for existence.commandis uninitialised, unless that code has been omitted?tokens).