I wanna split a string by '/' and change char '/' to '/0' in the string, so I wrote a function like this:
void parse_query(char* str){
char* p = str;
char** r = (char**)malloc(sizeof(char*)*5);
int i = 0;
r[i++] = p;
while(p=strchr(p,'/')){
*p = '/0';
p++;
r[i++] = p;
}
}
When I ran the program like below:
char* s = "a/b";
parse_query(s);
the segmentation fault occurred at this line:
*p = '/0';
Can anyone give me a suggestion?