here is my code:
#include <stdio.h>
#include <stdlib.h>
void AverageOfAss(float marks[][101], int numStudents, int numAss, float *avg[]) {
int i, j;
for (j=0; j<numAss; j++) {
*avg[j] = 0;
for (i=0; i<numStudents; i++) {
*avg[j] += marks[i][j];
*avg[j] = *avg[j]/(float)numStudents*100;
return ;
}
}
}
void PrintAvg(float *avg[], int numAss) {
int i;
for (i=0; i<numAss; i++) {
printf("Average for Exam %d = %.1f\n", i, *avg[i]);
return;
}
}
int main(int argc, char* argv[]) {
float grades[1001][101], avgAss[1001];
float *p;
int i, j, row, col;
p = avgAss;
row = atoi(argv[1]);
col = atoi(argv[2]);
FILE *input_grades;
input_grades = fopen("grades.txt", "r");
// READ IN GRADES
for (i=0; i<row; i++) {
for (j=0; j<col; j++) {
fscanf(input_grades, "%f, ", &grades[i][j]);
}
}
// OUTPUT GRADES LIST
printf("==================================\n");
printf("Student grades from the input file\n");
printf("==================================\n");
for (i=0; i<row; i++) {
printf("\n");
for (j=0; j<col; j++) {
printf("%.1f, ", grades[i][j]);
}
}
printf("\n\n");
AverageOfAss(grades, row, col, &avgAss);
PrintAvg(&avgAss, col);
fclose(input_grades);
}
Everything is alright except that when i tried to execute the code on the terminal, it showed some warnings:
incompatible pointer types passing 'float (*)[1001]' to parameter of type 'float **'
AverageOfAss(grades, row, col, &avgAss);
passing argument to parameter 'avg' here
void AverageOfAss(float marks[][101], int numStudents, int numAss, float *avg[]) {
incompatible pointer types passing 'float (*)[1001]' to parameter of type 'float **'
PrintAvg(&avgAss, col);
passing argument to parameter 'avg' here
void PrintAvg(float *avg[], int numAss) {
Does anyone know what happened to my codes? And how should i fix it? (newbie here)
return;buried in the body of the loops. I doubt you desired them to only iterate once, then return to the caller.