第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > c语言实现读取csv文件 并对数据进行分析。

c语言实现读取csv文件 并对数据进行分析。

时间:2021-09-21 04:38:51

相关推荐

c语言实现读取csv文件 并对数据进行分析。

总代码:

```c在这里插入代码片

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

struct Student

{

char shuzu[20];

}students[8][21];

int main()

{

int i=0,k=0,q=0;

FILE *fp = NULL;

char *line,*record;

char buffer[1024];

float a[8][21]={0};

if ((fp = fopen(“C:\Users\throb\Desktop\温度.csv”, “at+”)) != NULL)

{

fseek(fp, 0L, SEEK_SET); //定位到第二行,每个英文字符大小为1

char delims[] = “,”;

char *result = NULL;

int j = 0;

while ((line = fgets(buffer, sizeof(buffer), fp))!=NULL)//当没有读取到文件末尾时循环继续

{

record = strtok(line, “,”);

while (record != NULL)//读取每一行的数据

{

printf("%s ", record);//将读取到的每一个数据打印出来

strcpy(students[i][k].shuzu,record);

k++;

record = strtok(NULL, “,”);

j++;

}

i++;

k=0;

printf("\n");

j = 0;

}

fclose(fp);

fp = NULL;

}

for(i=0;i<8;i++)

{

for(k=0;k<21;k++)

{

a[i][k]=atof(students[i][k].shuzu);

}

}

printf("\n");

printf("=============\n");

for(i=2;i<8;i++)

{

for(k=1;k<21;k++)

{

if(a[i][k]>37.0)

{

printf("%s\n",students[i][0].shuzu);

printf("%s\n",students[0][k].shuzu);

printf("%s\n",students[i][k].shuzu);

q++;

}

}

}

printf("=============\n");

printf(“人数%d人”,q);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。