yoda
yoda

Reputation: 25

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().

Upvotes: 0

Views: 85

Answers (2)

Anoop Vaidya
Anoop Vaidya

Reputation: 46533

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?

Upvotes: 2

ouah
ouah

Reputation: 145829

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

d conversion specifier expects a pointer to int but you are passing an int.

To pass a pointer to the object use the & operator:

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

Upvotes: 3

Related Questions