I'm new to programming. So I don't know how to properly use the debugging tools. Xcode tells me that " Thread 1: EXC_BAD_ACCESS (code=1, address=0xffefbf3804)". I would really appreciate it if you could help me figure this out and fix the bug. The program must read the file .bmp, then I want to count the pixel brightness values and put them in an array[][] and work with them.
int main()
{
char* filename = (char*)("/…/second.bmp");
FILE* f = fopen(filename, "rb");
char info[54];
fread(info, sizeof(char), 54, f);
int width = *(int*)&info[18];
int height = *(int*)&info[22];
cout << " Name: " << filename << endl;
cout << " Width: " << width << endl;
cout << "Height: " << height << endl;
cout << endl;
int row_padded = (width * 3 + 3) & (~3);
unsigned char* data = new unsigned char[row_padded];
int array_bmp[height][width];
int arr_bmp[height][width];
for(int i = 0; i < height; i++)
{
fread(data, sizeof(char), row_padded, f);
for(int j = 0; j < width*3; j += 3)
{
// Y = 0.3 * R + 0.59 * G + 0.11 * B - яркость пикселя
// ============================
array_bmp[i][j] = 0.3 * (int)data[j+2] + 0.59 * (int)data[j+1] + 0.11 * (int)data[j]; // error message here
// ==========================
}
}
delete[] data;
fclose(f);
return 0;
}