I need a function that reads grades (integers) from from file and returns a dynamically allocated array in which they are stored.
This is what I have tried:
int *readGrades() {
int *grades;
int x;
scanf("%d", &x);
grades = malloc(x * sizeof(int));
return 0;
}
However I don't get anything when I run the code. The grades are stored in file called 1.in:
29
6 3 8 6 7 4 8 9 2 10 4 9 5 7 4 8 6 7 2 10 4 1 8 3 6 3 6 9 4
and I run my program using: ./a.out < 1.in
Can anyone tell me what I did wrong?
0rather thangrades). You haven't shown any code that'd try reading values from file.malloc()returns the pointer to allocated memory having garbage values, you yourself have to assign the values to allocated memory