c - what's wrong with the following code ? Getting error : Add is not a func or pointer -


only value of 1st row of matrix passing through add().i getting erroneous results.for eg : matrix 1 has elements 1,2,3,4 .however when print these values in add() ,i getting 1,2,0,0.

#include <stdio.h>  int main() {     int arr[100][100], arr1[100][100];      int m, n, x, y, z;      printf("\n enter order of matrix");     scanf("%d %d ", &m, &n);      //entry of matrix      printf("\n enter values of matrix 1");     (x = 0; x < m; x++)     {         (y = 0; y < n; y++)             scanf("%d ", &arr[x][y]);     }      printf("\n enter value of matrix 2 ");     (x = 0; x < m; x++)     {         (y = 0; y < n; y++)             scanf("%d ", &arr1[x][y]);     }      add(m, n, arr, arr1);      return 0; }  void add(int m, int n, int a[m][n], int b[m][n]) {        int x, y;     (x = 0; x < m; x++)     {         (y = 0; y < n; y++)             printf("%d     ", a[x][y]);         printf("\n");     } } 

in c, functions must declared before use , type of arguments must match between declaration , call.

in op's code, couple of 2d array declared as

int arr[100][100]; 

are passed function defined after main() as

void add(int m, int n, a[m][n], b[m][n]) { /* ... */ }   

generating 2 issues:

  • add() used in main(), it's not declared before, it's defined after.
  • arr , arr1 2d arrays of 100 x 100 ints, function add() written, accepts 2 variable length arrays of size m x n.

op have 2 ways fix, either change interface of function , declare before main(), this:

void add(int m, int n, a[][100], b[][100]);  // , define after main 

or change declarations of arr , arr1:

// includes...  void add(int m, int n, a[m][n], b[m][n]);    int main(void) {     int m, n;     // ...     // read n , m before using them declare 2 vla     int arr[m][n], arr1[m][n];      // ...      add(m, n, arr, arr1);      // ... }  void add(int m, int n, a[m][n], b[m][n]) {     // ...  }   

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -