// this is the grading sorting program for part one
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *fp; // file pointer, points to the file
char file_name[32]; // store file name
int ID[50];
int grade[50];
int a,b; // index variables
int student_id, grades;
// opening file by asking the user for the file name
printf("Enter the name of the file containing the grades\n");
scanf("%s",file_name);
fp=fopen("file_name", "r");
// read in data into the arrays
for (a = 0; a <= ID[50]; a++)
{
fscanf(fp,"%d", &student_id);
ID[a] = student_id;
for(b = 0; b <= grade[50]; b++)
{
fscanf(fp,"%d", &grades);
grade[b] = grades;
}
if(ID[a] == 0 && grade[b] == 0)
break;
}
fclose(fp);
return 0;
}
im trying to read data from a file by asking the user for the name of the file. when i input the name of the file and press enter it says: Segmentation fault PRESS enter. i don't what this problem is, im coding on ubuntu using codelite.
this is how the data looks like in the file
3050 76
2030 60
1600 70
2222 50
2430 60
2800 50
0 0
when the program reaches 0 0, it should stop reading, im not sure if this is the correct coding technique