帮我将数组传递给'C'中的函数 [英] Help me to pass arrays to functions in 'C'

查看:91
本文介绍了帮我将数组传递给'C'中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个与图论有关的程序,我通过使用函数编写了用于矩阵乘法的代码,效果很好.当我在程序中使用该功能时,出现以下错误.

我不明白为什么会这样?

在这里,我为您提供了整个程序中的部分代码.

I am writing a program related to Graph Theory, I wrote code for matrix multiplication by using functions, that worked well. when I am using that function into this program I am getting following errors.

I don''t understand why this is happening?

Here I am giving you the part of code from my whole program.

float product(int,int,int,int,float a[20][20],float b[20][20],float c[20][20]);
/*first to integers order of matrix a &
 second two integers are order of matrix b
 and float c is result of a*b */

float yn[ar][ar],temp[ar][ac];
product(ar,ac,ac,ac,incidence,yb,temp);/*calling function*/


float product(int ar,int ac,int br,int bc,float a[20][20],float b[20][20],float c[20][20])
{   int i,j,k;
  if(ac==br)
  {
    for(i=0;i<ar;i++)
    {
      for(j=0;j<bc;j++)
      {
        c[i][j]=0;
        for(k=0;k<ac;k++)
        {
          c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
        }
      }
      printf("\n");
    }
  }
  else
  {
    printf("Please Enter proper matrices");
    return -1;
  }
  return 0;
}


运行此命令时,出现这些错误.


When I run this, I am getting these errors.

prog.c: In function ‘main’:
prog.c:40: warning: passing argument 5 of ‘product’ from incompatible pointer type
prog.c:4: note: expected ‘float (*)[20]’ but argument is of type ‘int (*)[(unsigned int)(ac)]’
prog.c:40: warning: passing argument 6 of ‘product’ from incompatible pointer type
prog.c:4: note: expected ‘float (*)[20]’ but argument is of type ‘int (*)[(unsigned int)(ac)]’

推荐答案

我已经解决了这个问题.我做的是...

我已将float用作输入,但
我正在为int数组调用该函数.
这就是问题所在.
I have solved this problem my self. What I did is...

I have given float as inputs but
I am calling the function for int arrays.
that is the problem.


这篇关于帮我将数组传递给'C'中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆