the variable "students" is given by the user and then I have to use it in a function to find the max of a matrix. Note that "students" is the matrix's rows and I have to use it. "students" NEEDS to be included in the function's arguments. Also the better function isn't working properly and I cant figure out why. These are the compiler messages:
warning: passing argument 1 of 'better' from incompatible pointer type [-Wincompatible-pointer-types] 73 | int max = better(*grades,students);
note: expected 'int **' but argument is of type 'int *' 5 | int better(int **pin,int students){
I am also getting a warning for comparing a pointer to an integer in function better()
My inputed numbers are 1 2 0 0 0 0 3 5 1 10 and the max that is returned is equal to 2.
#include <stdio.h>
#define TESTS 5
int better(int **pin,int students){
int max = 0;
int k = 0;
for(int i = 0; i < students; i++){
for(int j = 0; j < TESTS; j++){
if(*(pin + k) >= 0 && *(pin + k) <= 10){
if(max < *(pin + k)){
max = *(pin + k);
}
}
k++;
}
}
return max;
}
int main(){
int students;
printf("Grades should always be a number between 0-10!\n\n");
printf("Enter number of students: ");
scanf("%d", &students);
int grades[students][TESTS], value;
for(int i = 0; i < students; i++){
for(int j = 0; j < TESTS; j++){
printf("Enter a value: ");
scanf("%d", &value);
if(value < 0){continue;}
if(value > 10){continue;}
grades[i][j] = value;
}
}
for(int i = 0; i < students; i++){
for(int j = 0; j < TESTS; j++){
if(grades[i][j] < 0 || grades[i][j] > 10){
grades[i][j] = 0;
}
}
}
for(int i = 0; i < students; i++){
for(int j = 0; j < TESTS; j++){
printf("%d ", grades[i][j]);
}
printf("\n");
}
int max = better(*grades,students);
printf("\nmax of grades is: %d", max);
return 0;
}
I'd appreciate it if sb could help me!