-2

I have been going through this: https://www.geeksforgeeks.org/draw-circle-c-graphics/ and for some reason it seems to not be working, I'm using vs 2019, I have the dependency's, no errors there, it seems its just the two quotes in initgraph(&gd, &gm, "");

error: E0167 argument of type "const char *" is incompatible with parameter of type "char *"

genpfault
  • 51,148
  • 11
  • 85
  • 139
CodingWiz
  • 31
  • 7
  • 5
    That's because the code is in C and you're trying to compile it as C++. These are different languages. – rustyx Feb 24 '22 at 16:00
  • 2
    I believe you need an old version of mingw to use this c code from 2005 that is a port of a 1980s / 1990s graphics library from turbo c. – drescherjm Feb 24 '22 at 16:04
  • 3
    Honestly, you shouldn't waste time trying to learn C++ at that site (even though the code is C, their C++ examples are almost always poorly written), waste time using a compiler that is almost 30 years old (Turbo C++), and waste time learning an outdated graphics system such as BGI, when there are modern systems you could learn that has value to them. – PaulMcKenzie Feb 24 '22 at 16:12
  • 3
    CodingWiz, take drescherjm's warning very seriously. Unless you've dug fairly deep in the search results when looking for a BGI library you'll have been pointed at codecutter's port, and that sucker was written for GCC 3 (GCC is on 11), Windows XP, and the graphics hardware and drivers of the time. If your computer is relatively up-to-date you can get the code exactly right and your program still might not work. If you MUST use BGI, [here's a link to an updated port](http://libxbgi.sourceforge.net/), but Paul's right. You're learning to fight tanks with a bronze-tipped spear. – user4581301 Feb 24 '22 at 16:18

1 Answers1

1

The third argument to initgraph should be a char* but in C++, "" is a const char[1].

void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);

You can get around that problem by creating a char[1] and use that as an argument instead:

char pathtodriver[] = "";
initgraph(&gd, &gm, pathtodriver);
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • hmm once I did that, it didint throw anything else but now there is a new error: int right: redefinition. – CodingWiz Feb 24 '22 at 16:09
  • links to this: `void printimage( const char* title=NULL, double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75, int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX, bool active=true, HWND hwnd=NULL );` int right=INT_MAX is the problem – CodingWiz Feb 24 '22 at 16:10
  • 1
    @CodingWiz You have _two_ `right` in that line - there can be only one! :-) – Ted Lyngmo Feb 24 '22 at 16:11
  • hmm, so which one should I use? – CodingWiz Feb 24 '22 at 16:11
  • @CodingWiz It's impossible for us to say. Please update your question with a [mre] if you don't think that this answer has answered the question you initially asked. – Ted Lyngmo Feb 24 '22 at 16:12
  • 1
    Ted, is it time for The Gathering already? – user4581301 Feb 24 '22 at 16:21
  • turns out I have an old version of the library's so lets hope thats it :/ – CodingWiz Feb 24 '22 at 16:21
  • 1
    Holy ground @user4581301 - Remember what Ramirez taught you! :-) – Ted Lyngmo Feb 24 '22 at 16:22
  • @CodingWiz Everything is old about that library. You should probably upgrade to a new development environment, but that's not the problem with your `printimage` above. You can't have two function parameters with the same name. – Ted Lyngmo Feb 24 '22 at 16:23
  • hmm what do ya recommend for a new dev enviroment? – CodingWiz Feb 24 '22 at 16:26
  • That depends on a lot of things. For Windows you have Visual Studio and C++Builder + a lot of others (mingw etc). For posix systems, `g++`, `clang++` etc. You'll also need a modern graphics library but I can't say much about that since I don't do graphics myself, but `SDL_bgi` could perhaps make the transition from your old library easy. – Ted Lyngmo Feb 24 '22 at 16:30
  • 1
    Hmm, I think I might try opengl, but first imma try SDL_bgi – CodingWiz Feb 24 '22 at 18:23
  • 1
    oh I didint mean to XD idk what happened there :/ – CodingWiz Apr 26 '22 at 23:50