所以我必须编写一个程序来对二维数组进行排序然后返回它,但我刚刚发现你不能从函数返回数组。我尝试对此进行研究,但没有解决问题。感谢您的帮助,谢谢。
下面是我编写的用于对垂直行进行排序的函数。
int vertSort(int matrix[][51], int size)
{
for(c=0;c<size;c++)
{
for(r=0;r<size-1;r++)
{
if(matrix[c][r]>matrix[c][r+1])
{
printf("Swap row %d column %d with row %d column %d", r, c, r, c)
int tmp=matrix[c][r];
matrix[c][r]=matrix[c][r+1];
matrix[c][r+1]=tmp;
}
}
}
return matrix;
}
最佳答案
您的代码不需要返回任何内容,它会修改调用方的数组副本。 (数组不能在 C 中按值传递)。将 int
返回类型更改为 void
,一切都会好起来的。
关于c - 如何从 C 函数返回二维数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26540795/