在 C 中将矩阵的列转换为单个向量的正确方法是什么?
int *column_to_row(int **a, int rows, int column_index)
{
// a is a the matrix,rows are the number of rows in the matrix
//column_index is the chosen column of the matrix to be turned into a vector
int i;
int *b=malloc(rows*sizeof(int));// b will be my returned vector
if(b==NULL)
{
exit(EXIT_FAILURE);
}
for(i=0;i<rows;i++)
{
b[i]=a[i][column_index];
}
return b;
}
我不断收到此 C2040 错误:
error C2040: 'column_to_row' : 'int *(int **,int,int,int)' 与 'int ()' 的间接级别不同
我是什么做错了吗?
int *column_to_row(int **a, int rows, int column_index)
{
// a is a the matrix,rows are the number of rows in the matrix
//column_index is the chosen column of the matrix to be turned into a vector
int i;
int *b=malloc(rows*sizeof(int));// b will be my returned vector
if(b==NULL)
{
exit(EXIT_FAILURE);
}
for(i=0;i<rows;i++)
{
b[i]=a[i][column_index];
}
return b;
}
I keep getting this C2040 Error:
error C2040: 'column_to_row' : 'int *(int **,int,int,int)' differs in levels of indirection from 'int ()'
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该功能工作正常。
它很可能会抱怨因为原型丢失了。
int *(int **,int,int,int)
看起来函数调用与声明不一致,因为它应该是int*(int **, int ,int)
>the function works correctly.
most likely it complains because the prototype is missing.
int *(int **,int,int,int)
looks like function call does not agree with declaration cause it should beint*(int **, int ,int)