"画像"の属性を計算するプログラムを作成しようとしています。 「画像」は0と1の2次元配列であり、0は空白、1は黒画素である。Cの3番目の関数で2つの異なる関数からポインタを使用する方法
私は高さを計算する必要があります。ピクセルの高さはpixelHeight/pixelWidthですが、ポインタの構文が正しいとは限りません。私は3番目の関数(tallness)で前の2つの関数のポインタを呼びたいと思います。
#include <stdio.h>
#include <math.h>
#define MAX_X 20
#define MAX_Y 20
int countBlackPixels(int image[MAX_X][MAX_Y]);
int findYPixel(int image[MAX_X][MAX_Y]);
int findXPixel(int image[MAX_X][MAX_Y]);
double findTallness(int image[MAX_X][MAX_Y]);
//function prototypes here
void processImage(int image[MAX_X][MAX_Y]) {
int nBlackPixels;
nBlackPixels = countBlackPixels(image);
printf("Pixel-count: %d\n", nBlackPixels);
int *pixelHeight;
*pixelHeight = findYPixel(image);
printf("Height: %d\n", *pixelHeight);
int *pixelWidth;
*pixelWidth = findXPixel(image);
printf("Width: %d\n", *pixelWidth);
double tallness;
tallness = findTallness(tallness);
printf("Tallness: %.6lf\n", tallness);
}
//Count Black Pixels
int countBlackPixels(int image[MAX_X][MAX_Y]) {
int x, y, blackPixelCount;
blackPixelCount = 0;
x = 0;
while (x < MAX_X) {
y = 0;
while (y < MAX_X) {
if (image[x][y] == 1) {
blackPixelCount = blackPixelCount + 1;
//printf("black pixel at x=%d y=%d\n", x, y); // example debug printf
}
y = y + 1;
}
x = x + 1;
}
return blackPixelCount;
}
//Height
//Loops through from bottom-left to the right, and then up
//through the Y axis, find the last occurance of Y,
//adds one to overcome array's zero count, and
//returns this value as the pixel height
int * findYPixel(int image[MAX_X][MAX_Y]) {
int x, y, *pixelHeight;
y = 0;
*pixelHeight = -1;
while (y < MAX_X) {
x = 0;
while (x < MAX_X) {
if (image[x][y] == 1) {
*pixelHeight = y+1;
}
x = x + 1;
}
y = y + 1;
}
return pixelHeight;
}
//Width
//Loops through from bottom-left to the top, and then across
//through the X axis, find the last occurance of X, adds 1
//to deal with array 0 count, and
//returns this value as the pixel width
int * findXPixel(int image[MAX_X][MAX_Y]) {
int x, y, *pixelWidth;
x = 0;
while (x < MAX_X) {
y = 0;
while (y < MAX_Y) {
if (image[x][y] == 1) {
*pixelWidth = x+1;
}
y = y + 1;
}
x = x + 1;
}
return pixelWidth;
}
//Tallness function
double findTallness(int *pixelWidth, int *pixelHeight) {
double tallness;
tallness = *pixelWidth/*pixelHeight;
printf("tall=%.6lf\n", tallness);
return tallness;
}
どこが間違っているのか誰にでも見られますか?
どのポインタですか?コンパイラから何のエラーが出ていますか、何を試していますか? –