0% found this document useful (0 votes)
40 views

C Graphic

The document discusses graphics programming in C language under MS-DOS. It explains that the graphics.h library is used to initialize graphics drivers and modes. The initgraph function in graphics.h is called to initialize graphics and accept parameters for the graphics driver, mode, and path. A sample program is provided that uses initgraph to initialize graphics, draws a line, and closes the graphics window.

Uploaded by

Akhilesh Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

C Graphic

The document discusses graphics programming in C language under MS-DOS. It explains that the graphics.h library is used to initialize graphics drivers and modes. The initgraph function in graphics.h is called to initialize graphics and accept parameters for the graphics driver, mode, and path. A sample program is provided that uses initgraph to initialize graphics, draws a line, and closes the graphics window.

Uploaded by

Akhilesh Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Graphics in C Language

We will restrict our discussion on Graphics in C Language to 16 bit C programming and MS DOS environment. In a C Program first of all you need to initialize the graphics drivers on the computer. This is done using the initgraph method provided in graphics.h library. In the next few pages we will discuss graphics.h library in details. Important functions in graphic.h library will be discuees in details and samples programmes will be provided to show the power of C programming language.

Graphics mode Initialization


First of all we have to call the initgraph function that will intialize the graphics mode on the computer. initigraph have the following prototype.

a sample program that initializes the graphics mode in C Language.

void initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver); #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; /* initialize graphics mode */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch();

exit(1); /* return with error code */ } /* draw a line */ line(0, 0, getmaxx(), getmaxy()); /* clean up */ getch(); closegraph(); return 0; }

You might also like