Pis*_*gan 1 c segmentation-fault multidimensional-array
我一直遇到分段错误,但我不确定这意味着什么或如何分辨它是什么原因(我对编程和C非常新).在main.c调用的这个函数中,我需要确定二维数组的eacg行中最小数字的索引.
这是我的代码:
#include "my.h"
void findfirstsmall (int x, int y, int** a)
{
int i;
int j;
int small;
small = y - 1;
printf("x = %3d, y = %3d\n", x, y); //trying to debug
printf("f. The first index of the smallest number is: \n");
for(i = 0; i < x; i++)
{
for(j = 0; j < y; i++) <---------- needs to be j, for any future readers
{
if(a[i][small] > a[i][j])
small = j;
printf("small = %3d\n", small); //trying to debug
}
printf("Row: %4d, Index: %4d\n", i, small);
small = y - 1;
printf("\n");
}
printf("\n");
return;
}
Run Code Online (Sandbox Code Playgroud)
它正确打印第一行,但不是第二行.这是我的阵列:
56 7 25 89 4
-23 -56 2 99 -12
这是我在运行程序时得到的:
Run Code Online (Sandbox Code Playgroud)x = 2, y = 5 f. The first index of the smallest number is: small = 4 small = 0 Segmentation fault
这是在C.提前感谢您的帮助!
| 归档时间: |
|
| 查看次数: |
698 次 |
| 最近记录: |