Graphics.h File For C

  • C Programming Tutorial
  • C Programming useful Resources
  • Selected Reading

The C graphics.h is the header file which should be included to initalize your computer to start using grahipcs methods and also to initialize the monitor.These kinds of statements before the main program are called preprocessor dierctives.Its very simple as coded below. Initializing Graphics Form Borland C graphics library. GitHub Gist: instantly share code, notes, and snippets.

Include graphics.h and winbgim.h. Copy and Past e the graphics.h and winbgim.h files into include folder of Code::Blocks directory. Path: C: Program Files (x86) CodeBlocks MinGW include. Didn't find what you were looking for? Copyright © 2000– JetBrains s.r.o. JetBrains s.r.o. If you want to use graphics.h on Ubuntu platform you need to compile and install libgraph. It is the implementation of turbo c graphics API on Linux using SDL. It is the implementation of turbo c graphics API on Linux using SDL.


A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.

You request to use a header file in your program by including it with the C preprocessing directive #include, like you have seen inclusion of stdio.h header file, which comes along with your compiler.

Including a header file is equal to copying the content of the header file but we do not do it because it will be error-prone and it is not a good idea to copy the content of a header file in the source files, especially if we have multiple source files in a program.

A simple practice in C or C++ programs is that we keep all the constants, macros, system wide global variables, and function prototypes in the header files and include that header file wherever it is required.

Include Syntax

Both the user and the system header files are included using the preprocessing directive #include. It has the following two forms −

This form is used for system header files. It searches for a file named 'file' in a standard list of system directories. You can prepend directories to this list with the -I option while compiling your source code.

This form is used for header files of your own program. It searches for a file named 'file' in the directory containing the current file. You can prepend directories to this list with the -I option while compiling your source code.

Include Operation

The #include directive works by directing the C preprocessor to scan the specified file as input before continuing with the rest of the current source file. The output from the preprocessor contains the output already generated, followed by the output resulting from the included file, followed by the output that comes from the text after the #include directive. For example, if you have a header file header.h as follows −

and a main program called program.c that uses the header file, like this −

the compiler will see the same token stream as it would if program.c read.

Once-Only Headers

If a header file happens to be included twice, the compiler will process its contents twice and it will result in an error. The standard way to prevent this is to enclose the entire real contents of the file in a conditional, like this −

This construct is commonly known as a wrapper #ifndef. When the header is included again, the conditional will be false, because HEADER_FILE is defined. The preprocessor will skip over the entire contents of the file, and the compiler will not see it twice.

Computed Includes

Sometimes it is necessary to select one of the several different header files to be included into your program. For instance, they might specify configuration parameters to be used on different sorts of operating systems. You could do this with a series of conditionals as follows −

But as it grows, it becomes tedious, instead the preprocessor offers the ability to use a macro for the header name. This is called a computed include. Instead of writing a header name as the direct argument of #include, you simply put a macro name there −

Dev

SYSTEM_H will be expanded, and the preprocessor will look for system_1.h as if the #include had been written that way originally. SYSTEM_H could be defined by your Makefile with a -D option.

graphics.h library is used to include and facilitate graphical operations in program. graphics.h functions can be used to draw different shapes, display text in different fonts, change colors and many more. Using functions of graphics.h you can make graphics programs, animations, projects and games. You can draw circles, lines, rectangles, bars and many other geometrical figures. You can change their colors using the available functions and fill them.

Examples:

Explanation :The header file graphics.h contains line() function which is described below :

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


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.

#include <graphics.h>
// driver code
{
// gm is Graphics mode which is a computer display
// DETECT is a macro defined in 'graphics.h' header file
// by loading a graphics driver from disk
line(150, 150, 450, 150);
// line for x1, y1, x2, y2
line(150, 250, 450, 250);
getch();
// closegraph function closes the graphics
// by graphics system .
}

Graphics.h File For Dev C++

Output:

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.

Recommended Posts:

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Graphics.h Header File For C

Please Improve this article if you find anything incorrect by clicking on the 'Improve Article' button below. Adobe acrobat pro free download mac.

Graphics.h File For Code Blocks