#include <stdio.h>
#include <string.h>
int split(char dst[3][1024], char* str, const char* spl);
int main() {
int i, num;
char a[3][1024];
for(i = 0; i<3; i++) memset(a[i], 0, sizeof(a[i]));
char str[] = "-aaa bbb ccc";
num = split(a, str, " ");
for(i=0; i<num; i++) printf("%s\n", a[i]);
return 0;
}
int split(char dst[3][1024], char* str, const char* spl) {
int n = 0;
char *result = NULL;
result = strtok(str, spl);
while( result != NULL )
{
strcpy(dst[n++], result);
result = strtok(NULL, spl);
}
return n;
}
输出
-aaa
bbb
ccc