the following code always stuck and the window hangs

91 views Asked by At
 #include<graphics.h>
 #include<conio.h>
 #include<stdlib.h>
  #include<dos.h>
  #include<alloc.h>

main()
  {
    int gd = DETECT, gm, area, temp1, temp2, left = 25, top = 75;
    void far *p;

    initgraph(&gd,&gm,"C:\\TurboC3\\BGI"); 
    rectangle(25,75,100,100);
    int sz=imagesize(25,75,100,100);
    p=farmalloc(sz);
    getch();

    temp1 = 200;
    temp2 = 200;

    getimage(left, top, left + 100, top + 100, p);
    putimage(left, top, p, XOR_PUT);
    getch();
    putimage(temp1 , temp2, p, XOR_PUT);

    getch();
    closegraph();
    return 0;
}

whenever I execute the above code the compiler stucks and windows hangs. I don't know how to use getimage() and putimage() properly . I want to design tetris in c so first getting hands on these functions

1

There are 1 answers

3
Weather Vane On

You have not allocated enough memory for the image, with

sz=imagesize(25,75,100,100);
p=farmalloc(sz);
...
getimage(left, top, left + 100, top + 100, p);

I suggest using this to get the image size

sz=imagesize(left, top, left + 100, top + 100);

which uses the same parameters as getimage().