Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
int num, lfl, lf, lc, cf, rc, rf, rfl;
int hlfl, hlf, hlc, hcf, hrc, hrf, hrfl;
int avg, avgr, avgl, hr, hrr, hrl, db, tp;
int type, surf, foul, cap, wspd, wdir;
int temp4, temp5, temp6, temp7, temp8, temp9, temp10;
int rain4, rain5, rain6, rain7, rain8, rain9, rain10;
char name[25], pic1[25], pic2[25];
char string[255];
FILE *infile;
/* Open the CSV File for reading */
infile = fopen("park.csv", "r");
if (infile == 0)
{
exit(1);
}
/* Read in the strings */
while (fgets(string, 255, infile) != NULL)
{
sscanf(string,"%d,%[^,],%[^,],%[^,],%d,%d,%d,
%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,
%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,
%d,%d,%d,%d,%d,%d,%d,%d,%d",num,name,pic1,pic2,
lfl,lf,lc,cf,rc,rf,rfl,hlfl,hlf,hlc,hcf,hrc,
hrf,hrl,avg,avgl,avgr,hr,hrl,hrr,db,tp,type,
surf,foul,cap,wspd,wdir,temp4,rain4,temp5,rain5,
temp6,rain6,temp7,rain7,temp8,rain8,temp9,rain9,
temp10,rain10);
/* Test Printf's */
printf("Number: %d\n",num);
printf("Name: %s\n",name);
printf("Average: %d\n",avg);
printf("WindSpd: %d\n",wspd);
printf("Temp 3: %d\n",temp7);
}
/* Close the CSV File */
fclose(infile);
}