array of pointers (string tokenizer)

Hello plz help.
i just want to tokenize the string and put into array of pointers (each holding a string) iam getting segmentation fault. plzz urgent

#include
#include
int main() {
char* st="abc,def,ghi";
char *str[10];
char *ch;
ch = strtok(st, ",");
int k=0;
while (ch != NULL) {
str[k]=(char*)malloc(20*sizeof(char));
strcat(str[k],ch);
ch = strtok(NULL, ",");
k++;
}
int l=0;
while(str[l]=NULL){
printf("%d
",str[l]);
l++;
}
return 0;
}
Edit/Delete Message

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion