2
 #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

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

0

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().

Weather Vane
  • 33,872
  • 7
  • 36
  • 56
  • i have done that now the system does not hangs but the compiler does . can you give me the entire code – user2992191 Jun 15 '15 at 05:36
  • No, sorry I can't because I don't have a compiler installed for what appears to be Borland code. But I am puzzled: your question says *" the compiler stucks and windows hangs"*. How can there be any executable if the compiler failed? And now you are saying *"the compiler [hangs]"*. What is different? Are you asking the right question? – Weather Vane Jun 15 '15 at 17:13
  • I'm sorry to puzzl you .But i was actually telling what happened or i was observing . Well, thanks now i have sorted the problem . i don't know how but i write the whole code again with some amendment and it worked. – user2992191 Jun 17 '15 at 13:56