I keep getting a segmentation fault, but I'm not sure what that means or how to tell what is causing it (I'm very new to programming and C). In this function, called by main.c, I need to determine the index of the smallest number in eacg row of a two-dimentional array.
Here is my code:
#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;
}
It prints correctly for the first row, but not the second. This is my array:
56 7 25 89 4
-23 -56 2 99 -12
This is what I am getting when I run the program:
x = 2, y = 5 f. The first index of the smallest number is: small = 4 small = 0 Segmentation fault
This is in C. Thanks in advance for the help!