子功能中的C分段故障:我如何知道要修复的内容?什么是分段错误?

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

这是我在运行程序时得到的:

x =   2, y =   5 
f.  The first index of the smallest number is:  
small =   4  small =   0 
Segmentation fault
Run Code Online (Sandbox Code Playgroud)

这是在C.提前感谢您的帮助!

Pri*_*ley 5

修复typo:

       for(j = 0; j < y; j++)
                         ^^
Run Code Online (Sandbox Code Playgroud)