yodh yodh - 2 months ago 15
C Question

c program on 2d matrices crashes everytime

int main(){
int m1[3][3],m2[3][3],m3[3][3],m4[3][3],m5[3][3];
create(m1);
create(m2);
matadd(m3,m1,m2);
matmul(m4,m1,m2);
transpose(m5,m4);
getch();
return 0;
}

void create(int a[3][3]){
int i,k;
for(i=0;i<3;i++){
for(k=0;k<3;k++)
scanf("%d",a[i][k]);
}
}


m new at coding,have made a simple program on 2D matrices,compiles successfully but every time on running it crashes after i input 1st 2 integers calling 1st create().

Answer

use this way

scanf("%d", &a[i][k]);

Every time you take input/scanf you need to put &. this is the basic thing of C, how can you miss this?

Comments