Tuesday, March 17, 2015

How to run C graphics program in Code::Block

In this post I am going to illustrate the process to run C graphics program in Code::Block. If you want to run C graphics in Dev-C++, you may check out my previous blog post on how to run C graphics program in Dev-C++.

Process:


1) Download the Code::Blocks EDU-Portable Version(CodeBlocks-EP) and Install It.
   (http://codeblocks.codecutter.org/)

2) Create a new project on CodeBlocks-EP
    (File->New->project...-> Select WinBGIm Project Category->Click on Go->Next)

         

3) Then give your project name(say my_first_gproject) and click on Next->Finish


        

4) Add a file(say test_prog.c) to project
   (File->New->Empty FIle->Yes->test_prog.c->Save)


         

         

         

5) Write the following code on first_prog.c:

   #include<stdio.h>
   #include<conio.h>
   #include<graphics.h>

   int main()
   {
       int gMode, gDriver = DETECT;

       initgraph(&gDriver, &gMode, "");

       line(0, getmaxy()/2, getmaxx(),getmaxy()/2);
       line(getmaxx()/2, 0, getmaxx()/2,getmaxy());

       circle(getmaxx()/2, getmaxy()/2, 130);

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

6) Compile and run program




















>>To learn more about C graphics program, you may visit the following links: 

   !!!Happy Coding!!!

Sunday, March 15, 2015

How to run C graphics program in Dev-C++

There are two ways to run C graphics program in Dev-C++:

First Process:

1) Download (http://bloodshed-dev-c.en.softonic.com/) and install Dev-C++.

2) Download WinBGIm 6.0 Dev-C++ package from      

     (http://www.nextwap.net/file/sRPS3XPN/winbgim-60-1g17l.html)

3) To Install WinBGIm 6.0 Dev-C++ package, go to Tools->Package Manager

            
            

Then Click ->Install Package->Add WinBGIm 6.0 Dev-C++ Package->Open->Next->Finish


4) Go to File->New->Project->Select WinBGIm->Project Name(my_first_gproject)->Ok

           

5) Write the following code:

               #include<stdio.h>
      #include<conio.h>
      #include<graphics.h>
      int main()
      {
        int gDriver=DETECT, gMode, midx=0,midy=0;
        initgraph(&gDriver, &gMode, " ");

        midx=getmaxx()/2;

        midy=getmaxy()/2;

        line(0,midy,getmaxx(),midy);

        line(midx,0,midx,getmaxy());

        circle(midx, midy, 100);


        getch();

        closegraph();
        return 0;
     }


6) Compile and run the program.
         
   

Second Process:

1) Download (http://bloodshed-dev-c.en.softonic.com/) and install Dev-C++.

2) Download WinBGIm (http://winbgim.codecutter.org/)

3) Extract the zip file.(Contains graphics.h winbgim.h and libbgi.a)

4) Copy graphics.h and winbgim.h files in include folder(C:\Dev-Cpp\include\) of your compiler directory.

5) Copy libbgi.a to lib folder (C:\Dev-Cpp\lib\) of your compiler directory.

6) Now Open Dev-C++ and create a new project. (Go to File-> New-> Project-> Project Name(my_first_gproject)->Ok)


           

7) Go to Project Menu->Project Options->Parameters

8) Copy the following code in the Linker field and click ok.

         -lbgi
        -lgdi32
        -lcomdlg32
        -luuid
        -loleaut32
        -lole32


           

9) Add a new file(first.c) to the project

            

10) Write the following code on first.c file:


        #include<stdio.h>
      #include<conio.h>
      #include<graphics.h>

      int main()
      {
        int gDriver=DETECT, gMode, midx=0,midy=0;

        initgraph(&gDriver, &gMode, " ");

        midx=getmaxx()/2;

        midy=getmaxy()/2;

        line(0,midy,getmaxx(),midy);

        line(midx,0,midx,getmaxy());

        circle(midx, midy, 100);


        getch();

        closegraph();
        return 0;
     }
11) Compile and run the program.

           


>>To know more about C graphics program, you may visit the following links:


     !!!Happy Programming!!!