用的是C,不是C++,最近在编大小不定的矩阵乘法的子函数,希望子函数返回乘后的新“矩阵”和矩阵的“行数”、“列数”,打算用一个数组返回指针的地址、行数和列数。下面是我自己在练习时遇到的问题,程序虽然能输出正确的值,但是有警告,分别出在“ARR[0]=p”和“p1=ARR[0]”,请问这个问题怎么解决?需要我的子函数返回结构体嘛?结构体的第一个存指针,后两个存整数?求问应该怎么解决这两个警告:
In function 'A':
[Warning] assignment makes integer from pointer without a cast
In function 'main':
[Warning] assignment makes pointer from integer without a cast
#include <stdlib.h>
#include <stdio.h>
int m=5;//行数
int n=3;//列数
void Print_mat(int **A,int Row_A,int Line_A)
//子函数:打印数组
{
int i,j;
for(i=0;i<Row_A;i++)//
{
for(j=0;j<Line_A;j++)
{
printf("%4d",A[i][j]);
if ((j!=0)&(j%(Line_A-1)==0) )
printf("\n");
}
}
}
int *A(int **p,int m,int n)
//子函数A,更改数组内部的值
{
int * ARR;
ARR=(int*)calloc(3,sizeof(int));
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
p[i][j]=p[i][j]-1;
}
}
printf("函数内部新指针p的地址是:%d\n",p);
ARR[0]=p;ARR[1]=m;ARR[2]=n;
return ARR;
}
int main()
{
int *ARR,**p,**p1,i;
p=(int**)calloc(m,sizeof(int*));//创建二级指针,是整个数组的首地址
for(i=0;i<m;i++)
{
p[i]=(int*)calloc(n,sizeof(int));//创建一级指针,是每一行的首地址
}
printf("原始数组如下:\n");
Print_mat(p,m,n);
ARR=A(p,m,n);//调用函数
p1=ARR[0];
printf("新数组如下:\n");
Print_mat(p1,m,n);
}
--
FROM 111.193.229.*