#include
int main(){
FILE *fp = NULL;
char *line,*record;
char buffer[1024];
//char path[MAX_BUF];
//char fullpath[1024];
//getcwd(path, MAX_BUF);
//printf("Current working directory: %sn", path);
int rowPos = 0;
int colPos = 0;
char param[1024];
if((fp = fopen("test.csv", "r")) != NULL)
{
while ((line = fgets(buffer, sizeof(buffer), fp))!=NULL)//当没有读取到文件末尾时循环继续
{
//删除换行
line[strlen(line) - 1] = ' ';
//跳过第一行
rowPos++;
if(rowPos==1){
continue;
}
//[,]分隔
record = strtok(line, ",");
colPos = 0;
//参数初期化
memset(param,0x00,sizeof(param));
while (record != NULL)//读取每一行的数据
{
//跳过行头
if( colPos > 0){
strcat(param,",'");
strcat(param,record);
strcat(param,"'");
}
colPos++;
record = strtok(NULL, ",");
}
//去除先头的【,】
strcpy(param,param+1);
printf("%s n", param);//将读取到的每一个数据打印出来
}
fclose(fp);
fp = NULL;
}
}



