this is the source code, the compiler(myngw,gcc) doesnt warn me about anything, but when i start the program it crashes.
Code:
#include <stdio.h>
#include <stdlib.h>
int matrixmax(int height,int width,int** tomb){
int i,j,max=0;
for(i=0;i<height;i++){
for(j=0;i<width;j++){
if(tomb[i][j]>max){
max=tomb[i][j];
}
}
}
return max;
}
int main() {
int i,j,height=2,width=3;
int** tomb;
tomb=malloc(height*sizeof(int*));
for(i=0;i<height;i++){
tomb[i]=malloc(width*sizeof(int));
}
for(i=0;i<height;i++){
for(j=0;j<width;j++){
tomb[i][j]=rand()%100+1;
}
}
printf("%d",matrixmax(height,width,tomb));
for(i=0;i<height;i++){
free(tomb[i]);
}
free(tomb);
}
the program allocates some memory for a 2d array, and then a function finds the max value and returns it.