【发布时间】:2016-12-19 19:35:31
【问题描述】:
我想更改函数内部一些结构变量的值。
这是我的变量声明:
BMPCOLOR **tBMPImg;
BMPCOLOR **tBMPGrey;
这是我在主函数中的函数调用:
greyscale(tBMPImg, tBMPGrey, &tBMPInfoblock, &tBMPHeader);
在这里你可以看到我想要改变变量值的函数:
void greyscale(BMPCOLOR ***tBMPImg, BMPCOLOR ***tBMPGrey, BITMAPINFORMATIONSBLOCK *tBMPInfoblock, BITMAPFILEHEADER *tBMPHeader) { //Grau = 0,299*Rot + 0,587*Grün + 0,144*Blau
double dGrey;
int iX;
int iY;
FILE *fpGrey;
fpGrey=fopen("grau.bmp", "w+");
fwrite(tBMPHeader, sizeof(&tBMPHeader), 1, fpGrey); //probably wrong too
fwrite(tBMPInfoblock, sizeof(&tBMPInfoblock), 1, fpGrey);
for(iX=0;iX<tBMPInfoblock->lbiWidth;iX++) {
for(iY=0;iY<tBMPInfoblock->lbiHeight;iY++) {
dGrey=0.299* tBMPImg[iY][iX]->cRed + 0.587 * tBMPImg[iY][iX]->cGreen + 0.144 * tBMPImg[iY][iX]->cBlue; //Error: "error reading variable dGrey"
tBMPGrey[iY][iX]->cRed=dGrey; //i guess something is with those pointers wrong
tBMPGrey[iY][iX]->cGreen=dGrey;
tBMPGrey[iY][iX]->cBlue=dGrey;
}
}
for(iX=0;iX<tBMPInfoblock->lbiWidth;iX++) {
for(iY=0;iY<tBMPInfoblock->lbiHeight;iY++) {
fputc(tBMPGrey[iY][iX]->cBlue,fpGrey);
fputc(tBMPGrey[iY][iX]->cGreen,fpGrey);
fputc(tBMPGrey[iY][iX]->cRed,fpGrey);
}
fwrite("0", tBMPInfoblock->lbiWidth % 4,1,fpGrey);
}
fclose(fpGrey);
我在 main 中使用指向 struct 的指针,但我不知道如何在另一个函数中处理它。在其他情况下,例如:How to work with pointer to pointer to structure in C? 是解决方案(*foo)->member = 1;,但它在我的程序中不起作用。
我已经读到在这种情况下我必须使用指向指针的指针。 我想问题是我只是从变量中获取地址。
【问题讨论】: