fork download
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #include <math.h>
  6. #define Pi 3.1415926536
  7. // this function initializes graphics mode
  8. // it will work only if you're using Borland C++ compiler & BGI drivers
  9. // if you're using another compiler you should overwrite body of this function
  10. void init_gr(void)
  11. {
  12. /* request autodetection */
  13. int gdriver = DETECT, gmode, errorcode;
  14. /* initialize graphics mode */
  15. initgraph(&gdriver, &gmode, "");
  16. /* read result of initialization */
  17. errorcode = graphresult();
  18. if (errorcode != grOk) /* an error occurred */
  19. {
  20. printf("Graphics error: %s\n", grapherrormsg(errorcode));
  21. printf("Press any key to halt:");
  22. getch();
  23. exit(1); /* return with error code */
  24. }
  25. }
  26. // this function shuts graphics mode down
  27. // it will work only if you're using Borland C++ compiler & BGI drivers
  28. // if you're using another compiler you should overwrite body of this function
  29. void end_gr(void)
  30. {
  31. closegraph();
  32. }
  33. // this function moves CP to (x,y) position
  34. // it will work only if you're using Borland C++ compiler & BGI drivers
  35. // if you're using another compiler you should overwrite body of this function
  36. void MoveTo(int x, int y)
  37. {
  38. moveto(x,y);
  39. }
  40. // this function draws a line to (x,y) position
  41. // it will work only if you're using Borland C++ compiler & BGI drivers
  42. // if you're using another compiler you should overwrite body of this function
  43. void LineTo(int x, int y)
  44. {
  45. lineto(x,y);
  46. }
  47. const N=6; // number of points in the figure
  48. // coordinates of all given points
  49. enum actions {MOVE,DRAW};
  50. struct
  51. {
  52. actions action;
  53. int x;
  54. int y;
  55. } figure[N]={{MOVE,360,270},{DRAW,360,260},{DRAW,355,260},{DRAW,360,250},
  56. {DRAW,365,260},{DRAW,360,260}};
  57. int x0,y0,dx,dy;
  58. float phi;
  59. int main(void)
  60. {
  61. // initializing graphics mode
  62. init_gr();
  63. // rotating about (x0,y0)
  64. x0=300;
  65. y0=260;
  66. // by 10 degrees
  67. phi=45.0*Pi/180.0;
  68. // main loop
  69. for(int i=0;i<8;i++)
  70. {
  71. // rotating the figure
  72. for (int j=0;j<N;j++)
  73. {
  74. dx=figure[j].x-x0;
  75. dy=figure[j].y-y0;
  76. figure[j].x=x0+dx*cos(phi)-dy*sin(phi);
  77. figure[j].y=y0+dx*sin(phi)+dy*cos(phi);
  78. }
  79. // drawing rotated figure
  80. for (j=0;j<N;j++)
  81. if (figure[j].action==MOVE)
  82. MoveTo(figure[j].x,figure[j].y);
  83. else
  84. LineTo(figure[j].x,figure[j].y);
  85. }
  86. // clean up
  87. getch();
  88. end_gr();
  89. return 0;
  90. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘init_gr’:
prog.c:13:19: error: ‘DETECT’ undeclared (first use in this function)
     int gdriver = DETECT, gmode, errorcode;
                   ^~~~~~
prog.c:13:19: note: each undeclared identifier is reported only once for each function it appears in
prog.c:15:5: error: implicit declaration of function ‘initgraph’ [-Werror=implicit-function-declaration]
     initgraph(&gdriver, &gmode, "");
     ^~~~~~~~~
prog.c:17:17: error: implicit declaration of function ‘graphresult’ [-Werror=implicit-function-declaration]
     errorcode = graphresult();
                 ^~~~~~~~~~~
prog.c:18:22: error: ‘grOk’ undeclared (first use in this function)
     if (errorcode != grOk) /* an error occurred */
                      ^~~~
prog.c:20:36: error: implicit declaration of function ‘grapherrormsg’ [-Werror=implicit-function-declaration]
     printf("Graphics error: %s\n", grapherrormsg(errorcode));
                                    ^~~~~~~~~~~~~
prog.c:20:30: error: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Werror=format=]
     printf("Graphics error: %s\n", grapherrormsg(errorcode));
                              ^
prog.c:22:5: error: implicit declaration of function ‘getch’ [-Werror=implicit-function-declaration]
     getch();
     ^~~~~
prog.c: In function ‘end_gr’:
prog.c:31:5: error: implicit declaration of function ‘closegraph’ [-Werror=implicit-function-declaration]
     closegraph();
     ^~~~~~~~~~
prog.c: In function ‘MoveTo’:
prog.c:38:5: error: implicit declaration of function ‘moveto’ [-Werror=implicit-function-declaration]
     moveto(x,y);
     ^~~~~~
prog.c: In function ‘LineTo’:
prog.c:45:5: error: implicit declaration of function ‘lineto’ [-Werror=implicit-function-declaration]
     lineto(x,y);
     ^~~~~~
prog.c: At top level:
prog.c:47:11: error: type defaults to ‘int’ in declaration of ‘N’ [-Werror=implicit-int]
     const N=6; // number of points in the figure
           ^
prog.c:52:5: error: unknown type name ‘actions’
     actions action;
     ^~~~~~~
prog.c:55:7: error: variably modified ‘figure’ at file scope
     } figure[N]={{MOVE,360,270},{DRAW,360,260},{DRAW,355,260},{DRAW,360,250},
       ^~~~~~
prog.c:55:33: error: excess elements in array initializer [-Werror]
     } figure[N]={{MOVE,360,270},{DRAW,360,260},{DRAW,355,260},{DRAW,360,250},
                                 ^
prog.c:55:33: note: (near initialization for ‘figure’)
prog.c:55:48: error: excess elements in array initializer [-Werror]
     } figure[N]={{MOVE,360,270},{DRAW,360,260},{DRAW,355,260},{DRAW,360,250},
                                                ^
prog.c:55:48: note: (near initialization for ‘figure’)
prog.c:55:63: error: excess elements in array initializer [-Werror]
     } figure[N]={{MOVE,360,270},{DRAW,360,260},{DRAW,355,260},{DRAW,360,250},
                                                               ^
prog.c:55:63: note: (near initialization for ‘figure’)
prog.c:56:5: error: excess elements in array initializer [-Werror]
     {DRAW,365,260},{DRAW,360,260}};
     ^
prog.c:56:5: note: (near initialization for ‘figure’)
prog.c:56:20: error: excess elements in array initializer [-Werror]
     {DRAW,365,260},{DRAW,360,260}};
                    ^
prog.c:56:20: note: (near initialization for ‘figure’)
prog.c: In function ‘main’:
prog.c:80:10: error: ‘j’ undeclared (first use in this function)
     for (j=0;j<N;j++)
          ^
cc1: all warnings being treated as errors
stdout
Standard output is empty