我目前正在尝试使用 strsep 读取 csv 文件,但它从未通过第一行
int main(){
FILE *fp = fopen("users100.csv", "r");
if(!fp){
printf("Erro");
return 0;
}
char *str;
str = (char *) malloc(10240);
while(fgets (str, 10240, fp) != NULL){
char *tmp = strdup(str);
char *token;
char **sp = &str;
sp = &tmp;
while(token = strsep(&str, ";")){
printf("%s ", token);
}
putchar('\n');
}
free(str);
fclose(fp);
return 0;
}
这个程序的输出是
public_repos id followers follower_list type following_list public_gists created_at following login
Segmentation fault (core dumped)
它打印第一行,但不打印其余部分。
谢谢!