Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The section of function is never entered in the following code please help me out!

#include<stdio.h>
int findMax(int *a[], int m, int n)//this function is not entering
{
    int i,j,k=0;
    for(i=0;i<m;i++)
      for(j=0;j<n;j++)
        if(k<a[i][j])
           k=a[i][j];
    printf("hi");//this hi is also not printing
                 //this hi is just for testing
    return k;
}

//This function correct it if possible

int main()
{
   int m,n,a[50][50],i,j,k=0;
   printf("Enter the number of rows in the matrix
");
   scanf("%d",&m);
   printf("Enter the number of columns in the matrix
"); 
  scanf("%d",&n);
  printf("Enter the elements in the matrix
");
  for(i=0;i<m;i++)
    for(j=0;j<n;j++)
    {
      scanf("%d",&a[i][j]);
    } 
  printf("The matrix is");
  for(i=0;i<m;i++)
  {
     printf("
");
     for(j=0;j<n;j++)
       printf("%d ",a[i][j]);
  }
  k=findMax((int **)a,m,n);//statements after this is never running but no
                           //compilation errors
  printf("
The maximum element in the matrix is %d",k);
  return 0;
}

please help me out!! Thanks to you in advance!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
684 views
Welcome To Ask or Share your Answers For Others

1 Answer

what you are doing here: int findMax(int *a[], int m, int n) is trying to point at int 50 times, but you want to point at a variabile type int 50 times. therefor you want to decleare the pointer before you decleare the array.

use therefor:

int findMax(int (*a)[], int m, int n)

this should work now without the casting

just turn it into:

k=findmax(a,m,n);

here is a simple tutorial on the subject.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...