as the title says, my program crashes when i try to print a bidimensional array.
The error is surely printf
in function printarray
, but i couldn't understand why it lead to crash.
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#define COL 40
#define ROW 40
void printarray(int array[COL][ROW], int col, int row);
main (){
int n,m,p,q;
int array[COL][ROW];
printf("Dammi 2 numeri \n"); scanf("%d",&n); scanf("%d",&m);
do{
printf("Dammi 2 p[<n] e q[<m] \n"); scanf("%d",&p); scanf("%d",&q);
}while(p>=n || q>=m);
printf("Mi hai dato: n= %d m= %d p= %d q= %d \n",n,m,p,q);
int i,j;
int random;
srand(time(NULL));
for(i=0; i<=n;i++){
for(j=0; j<=m;j++){
do{
random = rand() % 10;
}while(random == 0);
printf("\n i am at array[%d][%d] with number: %d\n",i,j,random);
array[i][j] = random;
}
}
//printf("lol0 ->>>>>>>>>>>%d<--------",array[0][0]);
printarray(array[n][m],n,m);
system("PAUSE");
}
void printarray(int array[COL][ROW], int col, int row){
int i,j;
for(i=0; i<=col;i++){
//printf("lol3 %d",i);
for(j=0; j<=row; j++){
printf("%d",array[i][j]);
}
printf("\n");
}
}
here i am attaching the your program without any error. the problem was to calling the printarray function.