C language realizes reading csv files and analyzing the data.

Total code:

```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\temperature.csv", "at+")) != NULL)
{ fseek(fp, 0L, SEEK_SET); //Locate to the second line, the size of each English character is 1 char delims[] = “,”; char *result = NULL; int j = 0; while ((line = fgets(buffer, sizeof(buffer), fp))!=NULL)//The loop continues when the end of the file is not read { record = strtok(line, “,”);






while (record != NULL)//Read the data of each row
{

printf("%s ", record);//Print out every data read
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("number of people%d people",q);
}

Guess you like

Origin blog.csdn.net/weixin_45663946/article/details/107426288