Heres my code and I can't figure out why I keep getting a segmentation fault when I run the main. The main was prewritten and I didn't manipulate it. The function compiles without error and the data file that is scanned in exists in the directory.
double getMin(char csvfile[], char column[])
{
FILE *csvFile=fopen(csvfile, "r");
int i=isValidColumn(*column);
if(i==0)
return -1.0;
char line[3001];
fgets(line, 3001, csvFile);
double min=100.0;
char *start=line;
int chapter=0;
int count=0;
int section=0;
char activity;
char assign[50];
char *ptr;
sscanf(column, "%c%d.%d", &activity, &chapter, §ion);
sprintf(assign, "%d.%d - %c", chapter, section, activity);
while(1){
char *token=strsep(&start, ",");
if(token==NULL)
break;
ptr=strstr(token, assign);
count=count+1;
if(ptr)
break;
}
double val=0;
while(fgets(line, strlen(line), csvFile))
{
char *token;
char *start=line;
char rank[50]={0};
for(i=0; i<count; i++)
token=strsep(&start, ",");
if(isdigit(token[0])) strcpy(rank, token);
sscanf(rank, "%lf", &val);
if(val<min) min=val;
}
fclose(csvFile);
return min;
}
Heres the CSV list--
Last name,First name,5.1 - Participation (11),5.2 - Participation (20),5.3 - Participation (3),5.4 - Participation (9),5.5 - Participation (5),5.6 - Participation (8),5.7 - Participation (9),5.8 - Participation (4),5.9 - Participation (5),5.10 - Participation (13),5.11 - Participation (21),5.12 - Participation (7),5.13 - Participation (3),5.14 - Participation (0),5.15 - Participation (0),5.1 - Challenge (0),5.2 - Challenge (9),5.3 - Challenge (0),5.4 - Challenge (14),5.5 - Challenge (2),5.6 - Challenge (0),5.7 - Challenge (8),5.8 - Challenge (0),5.9 - Challenge (2),5.10 -` Challenge (0),5.11 - Challenge (0),5.12 - Challenge (0),5.13 - Challenge (0),5.14 - Challenge (0),5.15 - Challenge (0),5.21 - Lab (10),5.23 - Lab (10),5.25 - Lab (10),5.26 - Lab (10),5.27 - Lab (10)
Aguilar,Maria,100,100,100,100,100,100,100,100,100,100,100,100,100,N/A,N/A,N/A,100,N/A,100,100,N/A,100,N/A,100,N/A,N/A,N/A,N/A,N/A,N/A,100,100,100,100,100
Alvarez,Abel,100,100,100,100,100,100,100,100,100,100,100,100,100,N/A,N/A,N/A,100,N/A,100,100,N/A,100,N/A,100,N/A,N/A,N/A,N/A,N/A,N/A,100,100,100,100,100
Andersen,Ronald,100,100,100,100,100,100,100,100,100,100,100,100,100,N/A,N/A,N/A,100,N/A,100,100,N/A,0,N/A,100,N/A,N/A,N/A,N/A,N/A,N/A,,,,,
Arias,Emory,100,100,100,100,100,100,100,100,100,100,100,100,100,N/A,N/A,N/A,100,N/A,100,100,N/A,100,N/A,100,N/A,N/A,N/A,N/A,N/A,N/A,100,100,100,100,100
Barrera,Lucien,100,100,100,100,100,100,100,100,100,100,100,100,100,N/A,N/A,N/A,100,N/A,92.85714286,50,N/A,75,N/A,50,N/A,N/A,N/A,N/A,N/A,N/A,,,,,
Column is entered as a LETTER Num.Num
to represent the activity and section number
ex. P5.4