I want to change the value of some struct variables inside of a function.
that's my declaration of my variables:
BMPCOLOR **tBMPImg;
BMPCOLOR **tBMPGrey;
that's my function call in the main function:
greyscale(tBMPImg, tBMPGrey, &tBMPInfoblock, &tBMPHeader);
Here you can see the function where i want to change the value of the variables:
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);
I use the pointer to pointer to struct in the main, but i dont know how to handle it in another function. In other cases like: How to work with pointer to pointer to structure in C? was the solution (*foo)->member = 1;
, but it didn't worked in my program.
I have read that i have to use pointer to pointer to pointer in that case. I guess the problem is that i just get the adress from the variables.