C语言进行csv文件数据的读取
C语言进行csv文件数据的读取:
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <math.h>
int main(){
FILE *fp = NULL;
char *line,*record;
char buffer[20450];//20450这个数组大小也要根据自己文件的列数进行相应修改。
if((fp = fopen("All-w.csv", "r")) != NULL)
{
fseek(fp, 16415L, SEEK_SET); //定位到第二行,每个英文字符大小为1,16425L这个参数根据自己文件的列数进行相应修改。
while ((line = fgets(buffer, sizeof(buffer), fp))!=NULL)//当没有读取到文件末尾时循环继续
{
record = strtok(line, ",");
while (record != NULL)//读取每一行的数据
{
printf("%s ", record);//将读取到的每一个数据打印出来
record = strtok(NULL, ",");
}
}
fclose(fp);
fp = NULL;
}
} 相关推荐
徐建岗网络管理 2020-07-28
lynjay 2020-06-14
AaronPlay 2020-06-13
拉斯厄尔高福 2020-11-04
嵌入式资讯精选 2020-10-15
zhaochen00 2020-10-13
penkgao 2020-10-13
wanshiyingg 2020-09-29
Mars的自语 2020-09-27
shenwenjie 2020-09-24
一个逗逗 2020-09-22
flycony 2020-09-13
zhaochen00 2020-08-20
Biao 2020-08-20
qingsongzdq 2020-08-19