Functions in C and Graphics

<stdio.h> :-file ‘stdio.h’ stands for Standard input-output, it is to be included at the beginning of the every C Program. (Functions in C and Graphics )

Download PDF Functions in C and Graphics Download PDF


<conio.h> :- This header file ‘conio.h’ stands for Console input-output, it uses somewhere in the program when the program doesn’t give proper output. it is also return type which work with function ‘getch();’ .

Graphics functions in c with syntax

<graphics.h> :-In the above program a ‘graphics.h’ the header file is included. This header file contains all prototype and the definition of all graphics functions. Before starting any Drawing action we need to initialize graphics mode.

 <dos.h>:- This DOS Disc Operating system, it is also a header file in C program for DOS type screen.

initgraph(); :- This function initialize the graphics system. Prototype is defined in ‘graphics.h’. It is declared as per given below.

 “void far initgraph (int far *gd , int far *gm, char far *path to driver);

gd (Graphics Driver)

gm (Graph Mode)” 

Circle(); :- This function Draw a circle at (x,y) of the given radius. This function is declared as under.void far circle(int x, int y, int radius); ‘or’circle(getmaxx, getmaxy, radius); .

getmaxx(); :- This function return maximum X coordinate on the screen. Its Prototype is defined in ‘graphics.h’ . And declared as far getmaxx (void);

getmaxy(); :- This function return maximum Y coordinate on the screen. Its Prototype is defined in ‘graphics.h’ . And declared as far getmaxy (void);

setcolor(); :- This function sets the current drawing color . This is declared as under.void for set color (int color);

closegraph(); :-This function shuts down the graphics system. The declaration is as under. Prototype is defined in ‘graphics.h’.void far closegraph(void); ‘or’ closegraph();

This was some important function of Any Graphics program. I hope you already know about other functions used in this program. Like

Types of functions in c

scanf(); :- It is used for taking input in C.

printf(); :- This function is use for print the output on screen.

getch(); :- This function work with Header file <conio.h>. It’s also an important function while your program doesn’t display proper output on Screen.

clrscr(); :- Clrscr stands for clear screen. After running any program, if you will show a rough Page with your Output. Then you can use this function to clear your Previous rough screen.

Note:- If you want to Increase ‘or’ Decrease space of Circle line then you can simply change here in For Loop:-
for(i=1;r>0;r=r-10,i++) //for less space r-5

arc:- “arc” function is used to draw an arc with center (x, y) and 1st angle specifies the starting angle, end angle specifies the end angle and the last parameter specifies the radius of the arc. arc function can also be used to draw a circle but for that starting angle and end angle should be 0 and 360 respectively.

Declaration:- void arc(int x, int y, int 1stangle, int endangle, int radius);

Circle:- circle function is used to draw a circle with center (x,y) and the third parameter specifies the radius of the circle.

Declaration:- void circle(int x, int y, int radius);

setcolor( ):-In Turbo C Graphics each color is assigned a number. A total of 16 colors are available. The number of available colors depend on the current graphics mode and driver.

For Example- BLACK is assigned 0, and BLUE is assigned 9  ( Instead of color value, you can put their name in capital Latter) etc.  setcolor function is used to change the current drawing color.

For Example- setcolor(BLUE) or setcolor(9) changes the current drawing color to RED. Remember that the default drawing color is WHITE.

Declaration:- void setcolor(int color);

ellipse :- Ellipse is used to draw an ellipse (x,y) are coordinates of the center of the ellipse, stangle is the starting angle, end angle is the ending angle, and the fifth and sixth parameters specify the X and Y radius of the ellipse. To draw a complete ellipse strangles and end angle should be 0 and 360 respectively.

Declaration:- void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);

getarccoords:-getarccoords function is used to get coordinates of arc which is drawn most recently. arccoordstype is a predefined structure which is defined as follows:-

Declaration:- void getarccoords(struct arccoordstype *var);

struct arccoordstype
int x, y;                     /*   center point of arc    */
int xstart, ystart;      /*   start position         */
int xend, yend;          /*   end position           */

The address of a structure variable of type arccoordstype is passed to function getarccoords.


getbkcolor();-Function getbkcolor returns the current background-color.

Declaration:- int getbkcolor();

E.g. color = getbkcolor(); // color is an int variable
If current background color is GREEN, color will be 2, or you can also use color name in capital latter.

getcolor();- getcolor function returns the current drawing color.

Declaration :- int getcolor();

E.g. a = getcolor(); // a is an integer variable
if current drawing color is WHITE then a will be 15. Functions in C and Graphics

 getimage();-getimage function saves a bit image of a specified region into memory, the region can be any rectangle.  getimage copies an image from screen to memory. Left, top, right, and bottom define the area of the screen from which the rectangle is to be copied, bitmap points to the area in memory where the bit image is stored.

Declaration:- void getimage(int left, int top, int right, int bottom, void *bitmap);

getmaxcolor();- function returns maximum color value for current graphics mode and driver. Total number of colors available for current graphics mode and driver are ( getmaxcolor() + 1 ) as color numbering starts from zero.

Declaration:- int getmaxcolor();

getpixel();- getpixel function returns the color of pixel present at location(x, y).

Declaration:- int getpixel(int x, int y);

gety();-gety function returns the y coordinate of current position.

Declaration:- int gety();

line();- line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and (x2,y2) are end points of the line.The code given below draws a line.

Declaration:- void line(int x1, int y1, int x2, int y2);

outtext();- outtext function displays text at current position.

Declaration:- void outtext(char *string);

outtextxy();-outtextxy function display text or string at a specified point(x,y) on the screen.

Declaration:- void outtextxy(int x, int y, char *string);
x, y are coordinates of the point and the third argument contains the address of the string to be displayed.

putpixel();-putpixel function plots a pixel at location (x, y) of the specified color.

Declaration:- void putpixel(int x, int y, int color);

For example, if we want to draw a GREEN color pixel at (35, 45) then we will write putpixel(35, 35, GREEN); in our c program, putpixel function can be used to draw circles, lines, and ellipses using various algorithms.

Sector();- sector function draws and fills an elliptical pie slice.

Declaration:- void sector( int x, int y, int stangle, int endangle, int xradius, int yradius);

setbkcolor();- setbkcolor function changes current background color e.g. setbkcolor(YELLLOW) changes the current background color to YELLOW.
Remember that default drawing color is WHITE and background color is BLACK.

Declaration:- void setbkcolor(int color);

Function in c

setfillstyle();- function sets the current fill pattern and fill color.

Declaration:- void setfillstyle( int pattern, int color);

Different fill styles are:-

enum fill_styles

For your best  experience Example with GRAPHICS PROGRAM Functions in C and Graphics

For your best experience Example with GRAPHICS PROGRAM

#include <stdio.h>

#include <graphics.h>

#include <conio.h>

     int gd = DETECT, gm;

 initgraph(&gd, &gm, “C:\\TC\\BGI“);

 setfillstyle(XHATCH_FILL, RED);

 circle(100, 100, 50);

floodfill(100, 100, WHITE);


 return 0;

Functions in c programming with examples pdf

setlinestyle:- This function is used to change the lining style.

Declaration of setlinestyle function:- void setlinestyle int linestyle, unsigned pattern, int thickness);

Available line styles:

enum line_styles

Settextstyle():- This function is used to change the way in which text appears, using it we can modify the size of text, change the direction of text, and change the font of the text.

Declaration:- void settextstyle( int font, int direction, int charsize);
font argument specifies the font of text, Direction can be HORIZ_DIR (Left to right) or VERT_DIR (Bottom to top).

Different fonts in C Language

enum font_names

textheight():-  This function returns the height of a string in pixels.

Declaration:- int textheight(char *string);

Textwidth();- This function returns the width of a string in pixels.

Declaration:- int textwidth(char *string);

Functions in C and Graphics

Color table,  setfillstyle and text color in c

Functions in C and Graphics
Functions in C and Graphics

Total number of color available depend on current graphics driver and mode. Use colors name in capital letters, for example,use setcolor(RED) not setcolor(red). The latter will give you an error. You may use number instead of COLOR for example, setbkcolor(GREEN) or setbkcolor(2) Both are same, but you are advised to use color name as it will improve readability of program.

Text color programm in C AND c++

int gd = DETECT, gm, drawing_color;
char a[100];


drawing_color = getcolor();

sprintf(a,”Current drawing color is RED “);
outtextxy( 10, 10, a );

return 0;


The output is given below:-

Functions in C and Graphics
Functions in C and Graphics


I hope you will understand better if you study at M.U, in the exam of M.U you know how important this “Functions in C and Graphics . So please don’t forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. Functions in C and Graphics or My website.

Our team check your every Comment per day Because your one feedback helps us in growing Thesmolt

I request you if you have any doubt or question regarding our site, then please don’t hesitate. We always waiting for your Suggestion.

Note:- If you want to Download This article’s in PDF form, then simply go (Top or Bottom of) Right corner and click on the PRINT icon, and it’s saved as a PDF of Functions in C and Graphics

For further questions, you can contact us Via mail [email protected]  otherwise, Our Help Page and Contact us Page, which is included below. I hope I’ll able to say all the possible ways to reach us. Or Download My Android Application Below Download Button.

thesmolt App

Best Regards Functions in C and Graphics , Kindly we request to you after Installing This Application, Please Don’t forget to give your feedback.

Note:- In this App, you can read also in Offline mode, When you Open a Post and After save (Right Corner) it.

Cheers Thesmolt




Leave a Reply