C语言中的bmp分割错误

C语言中的bmp分割错误,c,segmentation-fault,bmp,mandelbrot,C,Segmentation Fault,Bmp,Mandelbrot,我在一个正方形的框架中制作分形(Mandelbrot和BuddaBrot)的bmp图像,如果我把宽度增加到1000像素,没有问题,但是如果我把它的宽度增加到2000,我会在程序的第一行得到一个分割错误。发生了什么事。 这是我的密码: #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <math.h> #include <time.h> 由于堆栈太小,

我在一个正方形的框架中制作分形(Mandelbrot和BuddaBrot)的bmp图像,如果我把宽度增加到1000像素,没有问题,但是如果我把它的宽度增加到2000,我会在程序的第一行得到一个分割错误。发生了什么事。 这是我的密码:

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <time.h>

由于堆栈太小,无法在堆栈上分配2000*2000
pixel
s(行
screen视图;
),因此会出现堆栈溢出。Allcoate动态加载内存(使用
malloc


那么,我需要某种复杂的数据结构吗?不,你只需要使用
malloc
。怎么做?我要添加什么,在哪里添加?
#define HEIGHT 2000
#define WIDTH  2000




typedef struct _pixel{
unsigned char blue;
    unsigned char green;
unsigned char red;
}pixel;



typedef pixel screen[WIDTH][HEIGHT];

typedef struct _frame{
    pair width;
    pair height;
}frame;

void printPixel(screen view);


void editPixel(screen view, int row, int col, pixel p);
void blankScreen(screen view);


int main(int argc, const char * argv[])
{ 



    FILE *out; 
    out = fopen("Out.bmp", "w");


    int localHeight = HEIGHT - HEIGHT%4;
    int localWidth = WIDTH - WIDTH%4;
    frame myFrame = getFrame(localWidth,localHeight);

    assert((myFrame.height.small+myFrame.height.big*256)==HEIGHT - HEIGHT%4);
    assert((myFrame.width.small+myFrame.width.big*256)== WIDTH - WIDTH%4);

    unsigned char bmp[] = {
        0x42,0x4D,0x5A,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x3C,0x00,0x00,0x00,0x28,0x00,
        0x00,0x00,myFrame.width.small,myFrame.width.big,0x00,0x00,
        myFrame.height.small,myFrame.height.big,  
        0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
        0x00,0x00,0x24,0x00,0x00,0x00,0x13,0x0B,
        0x00,0x00,0x13,0x0B,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x99,
        0x00,0x00,0x00,0x00,};
        //Write the header
    fwrite(bmp, 1, sizeof(bmp), out);

    screen view;
    blankScreen(view); //clears the image to a blank

    printPixel(view); // this gets the image


    fwrite(view, 1, sizeof(screen), out); //writes the image
    fclose(out); //closes the file

    return EXIT_SUCCESS;
}
pixel * view;
view = malloc(sizeof(pixel) * HEIGHT * WIDTH);
if (view == NULL) return 1; //failed to allocate

// change those two functions to handle a "pixel *" instead of pixel[HEIGHT][WIDTH]
blankScreen(view);
printPixel(view);