-2

The question is the same above.

Since when I compile my C program it gives me a fatal error (graphics.h not found), I was wondering what I can use instead of it.

Consider that I DO NOT WANT links to other sites or whatever, because I'm a newbie and I wouldn't understand.

I just need the command to type, in order to make it work. If I have to download a library then it's fine, provided you guide me all through the process.

Thanks.

Here is what I am trying to compile

A code to create a smiley.

#include <graphics>

int main(void)
{
int midX, midY,
leftEyeX, rightEyeX, eyeY,
noseX, noseY,
headRadius,
eyeNoseRadius,
smileRadius,
stepX, stepY,

initwindow(500, 400, "Happy Face - press key to close", 200, 150);

midX = getmaxx() / 2;
midY = getmaxy() / 2;
headRadius = getmaxy() / 4;
circle(midX, midY, headRadius);

stepX = headRadius / 4;
stepY = stepX;
leftEyeX = midX - stepX;
eyeY = midY - stepY;
eyeNoseRadius = headRadius / 10;
circle(leftEyeX, eyeY, eyeNoseRadius);
circle(rightEyeX, eyeY, eyeNoseRadius);

noseX = midX;
noseY = midY + stepY;
circle(noseX, noseY, eyeNoseRadius);

smileRadius = (int)(0.75*headRadius + 0.5);
arc(midX, midY, 210, 330, smileRadius);

getch();
closegraph();

return(0);

}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Understanding
  • 119
  • 1
  • 1
  • 9
  • What are you hoping to gain from `graphics.h`? Is there some API / library that you're hoping to use? It would be worth mentioning it in your question. – Attie Mar 15 '17 at 11:12
  • `` is just a random filename - we need more of a clue. Why do you think you need it? Please choose C or C++ – Richard Critten Mar 15 '17 at 11:12
  • @RichardCritten I'm writing in C! – Understanding Mar 15 '17 at 11:22
  • 2
    Possible duplicate of [How can i add graphics.h library on my mac?](http://stackoverflow.com/questions/4881649/how-can-i-add-graphics-h-library-on-my-mac) – Jabberwocky Mar 15 '17 at 11:24
  • @AlanTuring then why did you add C++ tag to your question? – Gerhardh Mar 15 '17 at 11:34
  • @MichaelWalz Useless. – Understanding Mar 15 '17 at 11:51
  • @Attie Useless. – Understanding Mar 15 '17 at 11:51
  • 2
    @AlanTuring No... your question is useless - do you even know what you're trying to accomplish by including `graphics.h`? – Attie Mar 15 '17 at 11:53
  • @Attie Your useless link does not provide me any help or information. Do you want me to write here all the code I'm trying to compile? – Understanding Mar 15 '17 at 11:53
  • @AlanTuring a concise example, yes. http://stackoverflow.com/help/mcve – Attie Mar 15 '17 at 11:54
  • @AttieDone! The code is above! – Understanding Mar 15 '17 at 11:56
  • 1
    Did you find that code in a museum? I'm pretty sure I recognise those function calls. From 25 years ago from Borland compilers. The way we speak to hardware and the operating system changes over the years. You can't expect to use a library that worked on one compiler for DOS to work on something more modern. If you want that to work, you need to dig up a compiler and operating system that's equally old as the code you're trying to run. – Art Mar 15 '17 at 12:06
  • I got curious. I wasn't that far off with 25 years ago (since that was when I used it). The last product that supported that graphics interface was Borland C++ 5.02 which was released in 1997. – Art Mar 15 '17 at 12:13
  • @Art lol, well I was trying to follow some programs written on the book of Hanly and Koffman "problem solving and programming in C" but it says its from 2013... not that old! o.o – Understanding Mar 15 '17 at 12:22
  • 1
    @AlanTuring Sounds like they just keep reprinting an old book without updating it to more modern interfaces. Or maybe there exists a compatibility layer somewhere that simulates the old Borland Graphics Interface on some more modern compilers. There is no graphics interface that will work on all operating systems. The closest you can get is OpenGL or SDL. You can google tutorials for those. Or wait a bit until you learn more and stay with text output for now. – Art Mar 15 '17 at 12:27
  • BGI graphics were still used until the late 1990s, but then mostly for student purposes, as professionals were then moving over to Windows graphics. – Lundin Mar 15 '17 at 12:31
  • @Art The problem is: how to write a "modern" code for that? – Understanding Mar 15 '17 at 12:55
  • [Find out what each BGI function does](https://www.cs.colorado.edu/~main/bgi/doc/) and replace with similar functions from modern library. Or use [wrapper library](http://libxbgi.sourceforge.net/) with your modern library (note: I haven't used linked library). – user694733 Mar 15 '17 at 13:07

1 Answers1

9

graphics.h refers to the non-standard graphics library called BGI, designed by Borland in the year 1989 to be used with Borland compilers for the MS DOS operative system. It is not C standard, it is not portable. It cannot be used on any other system than DOS or early 32 bit Windows (95/98 etc), unless you use emulators.

If you wasted time learning about BGI, you were scammed by your teacher/school. As a beginner, you should forget all about MS DOS graphics and focus on things that are actually used in the real world, in the year 2017.

Lundin
  • 195,001
  • 40
  • 254
  • 396