Oh my!
Code:
// counts black pixels in row 1
int
row1Pixels(int digit_image[DIGIT_HEIGHT][DIGIT_WIDTH]) {
int column, black_pixels;
black_pixels = 0;
for (column = 0; column < DIGIT_WIDTH; column++) {
if (digit_image[1][column] == 1) {
black_pixels = black_pixels + 1;
}
}
return black_pixels;
}
// counts black pixels in all rows. This function is called 27 times,
// but that's not a bad thing.
int countBlackPixels(int digit_image[DIGIT_HEIGHT][DIGIT_WIDTH], int row) {
int column, black_pixels;
black_pixels = 0;
for (column = 0; column < DIGIT_WIDTH; column++) {
if (digit_image[row][column] == 1) {
black_pixels = black_pixels + 1;
}
}
return black_pixels;
}
The calling function will increment the value of the variable row (which would be the value of the customary variable 'i', in the following for loop:
Code:
int blackPixelSum=0;
int i;
for(i=0;i<DIGIT_HEIGHT;i++) {
blackPixelSum+=countBlackPixels(digit_image[DIGIT_HEIGHT][DIGIT_WIDTH], i);
}
So 'i' is i in the calling function, but in the countBlackPixels() function, 'i' becomes 'row'.
This isn't the only way to do this, but it's one good way to do it.