怎麼能分割字符串並將他們分別保存到字符串數組裡,c語言思路或者源代碼
#include <stdio.h>
#include <string.h>
void split(char **arr, char *str, const char *del) {
char *s = strtok(str, del);
while(s != NULL) {
*arr++ = s;
s = strtok(NULL, del);
}
}
int main() {
char str[] = "10,20,30";
char *arr[3];
const char *del = ",";
int i = 0;
split(arr, str, del);
while(i<3)
printf("%s\n", *(arr+i++));
}
http://codepad.org/J8qVPHiD