I'm stuck on my MAXROW is suppose to be 40 but everytime I input it I get a weird output. I'm pretty sure my counter is correct. Can someone please take a lookk and direct somehow.
#include <stdio.h>
#include <stdlib.h>
#define MAXROW 15
#define MAXCOL 6
#define ValuesPerLine 10
#define FLUSH fflush(stdin)
//Global declarations
void getData (int studentScores [][MAXCOL], int *rowcount, int *colcount);
void rowAverage (int studentScores [][MAXCOL], int rowcount, float rowAvrg[]);
void colAverage (int studentScores [][MAXCOL], int rowcount, float colAvrg[]);
void printTable (int studentScores [][MAXCOL], int rowcount, float rowAvrg [], float colAvrg[]);
int main (void)
{
//Local Declarations
FILE* studentGrades;
FILE* studentFinal;
int studentScores[MAXROW][MAXCOL];
int rowcount, colcount;
float rowAve [MAXROW] = {0.0};
float colAve [MAXCOL] = {0.0};
int mn [MAXCOL] = {0};
int mx [MAXCOL] = {0};
//Statements
getData (studentScores, &rowcount, &colcount);
rowAverage (studentScores, rowcount, rowAve);
colAverage (studentScores, rowcount, colAve);
printf("\n");
//printTable (studentScores, rowAve, colAve, lowGrade);
printTable (studentScores, rowcount, rowAve, colAve);
printf("\nend of program\n"); //closing statement
system("PAUSE");
return 0;
}//end of program
/* ===============================Get Data==================================
In this function we will get the data from the file and have it stored into the system
inorder to have the array of the file. The array will print out onto the screen.
The function will open the data file and read from file and when done will close
the file.
*/
void getData (int studentScores [][MAXCOL], int *rowcount, int *colcount)
{
FILE* studentGrades;
int row, col;
studentGrades = fopen("studentGrades.txt", "r"); //reads file
if ((studentGrades = fopen("studentGrades.txt", "r")) == NULL) //checks if file exists
{
printf("\aERROR OPENING studentGrades.txt\n");
exit (100);
}
for(row=0; row < MAXROW; ++row)
{
for(col=0; col < MAXCOL; ++col)
{
*rowcount = row;
*colcount = col;
fscanf(studentGrades, "%d", (*(studentScores+row)+col)); //Pointer notation.
//scanf("%d", (*(*(array+r)+c))); //This line shows an error!
}
}
// *rowcount = row;
// *colcount = col;
if (fclose(studentGrades)== EOF) //closing file
{
printf("\aError closing studentGrades.txt\n");
exit (102);
}// if close
return;
}
/* ===============================Row/Student Average==================================
This function will calculate the average of the students quiz 1, 2, 3 will be 50% of
the student grade while quiz 4 & 5 will be the other 50% of the student calculation
to get the students final grade
*/
void rowAverage (int studentScores [][MAXCOL], int rowcount, float rowAvrg[])
{
//Statements
for (int row = 0; row < rowcount; row++)
{
for (int col = 1; col < MAXCOL; col++)
//calculating the student average
rowAvrg [row] = (((studentScores [row][1] + studentScores[row][2] + studentScores[row][3]) /3.0) *0.5)+
(((studentScores [row][4] + studentScores [row][5]) /2.0) * 0.5);
}
return;
}
/* ===============================Colum/Quiz Average==================================
In this function we get the average of the quizzes. Example the class average of quiz 1,
quiz 2, quiz 3, quiz 4, and quiz 5. and will print it out as a one dimensional array
*/
void colAverage (int studentScores [][MAXCOL], int rowcount, float colAvrg[])
{
//Statements
for (int col = 1; col < MAXCOL; col++)
{
for (int row = 0; row < rowcount; row++)
//calculating the class average of quizzes
colAvrg[col] += (*(*(studentScores+row)+col));
colAvrg [col] /= rowcount;
}
return;
}
/*==============================Printing The table============================
This function will call the functions and print them out accordingly.
*/
void printTable (int studentScores [][MAXCOL], int rowcount, float rowAvrg [], float colAvrg[])
{
for (int row = 0; row < rowcount; row++)
{
for (int col = 0; col < MAXCOL; col++)
printf(" %5d", (*(*(studentScores+row)+col)) ); //prints out what was on the data file.
printf(" |%6.2f\n", rowAvrg [row]); // prints out student average
}
printf("\n");
printf("Average");
printf(" ");
for (int col = 1; col < MAXCOL; col++)
printf("%7.2f", colAvrg[col]); // prints out quiz averages
printf("\n\n");
return;
}