My problem..
a.) Create a float array using memory allocation to store the GPA scores of 10 students. Assign values to it (your choice)
b.) Find the maximum GPA in this array.
c.) Write the contents of this array to a file alloc.txt
d.) Expand the array to accommodate the GPA scores of 5 more students.
e.) Write the contents of this expanded array to another file realloc.txt
f.) Read the contents of realloc.txt to another float array named Expand.
g.) Print out the contents of Expand array.
So far I have..
#include <stdio.h>
#include <stdlib.h>
main ()
{
int i = 0;
float StudentGPA [9];
StudentGPA [0] = 3.7;
StudentGPA [1] = 2.9;
StudentGPA [2] = 3.8;
StudentGPA [3] = 2.5;
StudentGPA [4] = 3.4;
StudentGPA [5] = 1.9;
StudentGPA [6] = 2.4;
StudentGPA [7] = 4.0;
StudentGPA [8] = 3.1;
StudentGPA [9] = 3.9;
float *arrayStart = (float*) malloc(sizeof(float));
for (i=0; i<StudentGPA; i++) {
(*arrayStart + i);
}
float maxValue = *arrayStart;
for (int i=1; i<StudentGPA; i++) {
if ( *(arrayStart + i) > maxValue )
maxValue = *(arrayStart + i);
}
const char(0) fileName = "alloc.txt";
FILE* outputFile = fopen (fileName, "w");
if (outputFile) {
for (int i=0; i<StudentGPA; i++) {
printf(outputFile,"%.2f\n", *(arrayStart + i));
}
fclose(outputFile);
}
outputFile = NULL;
}
I am stuck here, I realize this isn't finished but I cannot further complete anymore. My compiler notifies multiple errors. Someone please help. Thank you ahead of time!