Software & Finance





C Programming (Turbo C++ Compiler) Graphics - Starting with Graphics





I have given a sample program on how to turn on graphics mode in Turbo C in MS-DOS 16 bit application.

If you get EGAVGA.BGI error in the output, then it means the file is not placed in the path.

 

Click here to download the sample code and .exe file. 

Look at the sample code and output.


Source Code


#include <stdio.h>

#include <graphics.h>

#include <stdlib.h>

#include <conio.h>

#include <bios.h> 

 

void main()

{

      int grd, grm;

      int num, xpos, ypos, i, j, index;

 

      detectgraph(&grd,&grm);

 

      initgraph(&grd, &grm, "");

 

      if( graphresult() != 0)

      {

            printf("Unable to find Graphics driver");

            return;

      }

 

      num = getmaxcolor();

      settextjustify(CENTER_TEXT, CENTER_TEXT);

      xpos = getmaxx() / 2;

      ypos = getmaxy() / 2;

 

      setbkcolor(BLUE);

      setcolor(WHITE);

      rectangle(1,1,getmaxx() - 1, getmaxy() - 1);

 

      for(j = 1; j <= 11; j++)

      {

            circle(30, j * 40, 18);

            circle(getmaxx() - 30, j * 40, 18);

      }

 

      index = 0;

      for(i = BLUE + 1; i < num; i++)

      {

            setcolor(i);

            outtextxy(xpos,50 + (index++ * 30),"Welcome to http://www.softwareandfinance.com");

      }

      getch();

      closegraph();

 

}

Output


The background color is solid BLUE.
Left and Right column with 11 circles in white color.
Welcome to http://www.softwareandfinance.com in different colors.
Everything will fit into a while color rectangle.