#include<stdio.h>
#include<string.h>
int main(){
FILE *fp = NULL;
char *line,*record;
char buffer[1024];
if((fp = fopen("menu.csv", "r")) != NULL)
{
fseek(fp, 20L, SEEK_SET); //定位到第二行,每个英文字符大小为1
char delims[] = ",";
char *result = NULL;
int j = 0;
while ((line = fgets(buffer, sizeof(buffer), fp))!=NULL)//当没有读取到文件末尾时循环继续
{
record = strtok(buffer, ",");
while (record != NULL)//读取每一行的数据
{
if (strcmp(record, "Ps") == 0)//当读取到Ps那一行时,不再继续读取
return 0;
printf("%s ", record);//将读取到的每一个数据打印出来
if (j == 9) //只需读取前9列
break;
record = strtok(NULL, ",");
j++;
}
printf("\n");
j = 0;
}
fclose(fp);
fp = NULL;
}
}
你自己打的回车啊...