传递指针变量到函数里面

来源:百度知道 编辑:UC知道 时间:2024/06/03 01:35:36
首先在主函数中有:
ptrA = readmatrix (filenameA, rowsA, columnsA);

调用了一下这个函数:

float** readmatrix(char filename[], int& rows, int& columns)
{
ifstream ins (filename, ios::in);

if (ins.good())
{
ins >> rows;
ins >> columns;

int i = 0;
int j = 0;
float **matrix = new float*[rows];
for (int k=0; k< columns; k++)
matrix[k] = new float[columns];

if (matrix == NULL)
{
cerr << "Memory allocated fail." << endl;
return NULL;
}

while (i < rows)
{
while (j < columns)
{
ins >> matrix[i][j];
j++;
}
j = 0;
i++;
}

ins.close();

return matrix;
}

else
return NULL;
}

结束后返回的值再调用进函数:
(主函数中:
printmatrix (ptrA, rowsA, columnsA);
)

把你的主程序main()贴上来才好给你看啊

看你的错误提示 好像是代码哪里写错了

错误是
(
Undefined reference to 'printmatrix(float*, int, int)'

而你的函数声明是
void printmatrix (float *matrix[], int columns, int rows)

第一个参数应该传递 float**的参数,

函数有返回值,是一个指向float型的指针的地址,在主函数中没有赋给任何变量啊