Borland C++ Graphics problem

Heretic_Cata

We're gonna live forever
Joined
Dec 27, 2005
Messages
9,587
Location
Romania
I'm trying to do anything in BGI graphics mode of borland C++ 3 and 5. And nothing works in either of them. Even the most basic examples don't work:

This was tried in BorlandC 3.

Code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy;
   int radius = 100;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "c:\\Docume~1\\INFO\\ANU2\\BORLANDC\\BGI");

   /* 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); /* terminate with an error code */
   }

   midx = getmaxx() / 2;
   midy = getmaxy() / 2;
   setcolor(getmaxcolor());

   /* draw the circle */
   circle(midx, midy, radius);

   /* clean up */
   getch();
   closegraph();
   return 0;
}
On compile - no error. On run no error. But it still doesn't do anything. By running the program in cmd i get an error EGAVGA.BGI driver device not found.


I have found a lot of people had this problem. Their problem was either - the path written wrong - mine being correctly writen; or they didn't check the graphics library thingy at the options, which i did; or they don't have egavga.bgi in the right place, and i copied it in every possible location in the program folder. What's more frustrating is that it doesn't work in BorlandC 5.2 either - the exact same error in cmd.
Yes, i could try learning windows graphics (OpenGL) to use in C, but i already know how to work with the bgi graphics since i worked with them a year ago. It worked perfectly then - but it was my old computer. Could this be the problem ?

Thanks
 
Why try to use something so ancient anyway? If you need simple 2D graphics, use an up to date library like Allegro.
 
Why try to use something so ancient anyway? If you need simple 2D graphics, use an up to date library like Allegro.
Well, i'm too lazy to learn somthing new. :(
What's that allegro you're talking about.

I just got visual studio 2008. It took 1 hour to install it ... I hope i'll get something out of this thing.

EDIT: ******ed question: how in GOD'S NAME do you compile and run something in this thing ?

EDIT2: nevermind that - i don't know how but i did it. And it only took 10 minutes yay.

EDIT3: nevermind the previous edit. It says it runs it, but i don't see any hello world. FAIL
 
The window is probably popping up and then closing when the program exits.

Either put a breakpoint on the closing brace of main (F9) or put a getchar or similar at the end.
 
The window is probably popping up and then closing when the program exits.

Either put a breakpoint on the closing brace of main (F9) or put a getchar or similar at the end.
Well you were right i forgot to do that. :lol: However i still don't see any result. :crazyeye:

The thing is i have a Compile options and a Test Run option. Everytime i test run it says the test was succesfull. However i've yet to find a just-******g-run option. Well there has to be other ******ed people on the web - i'll go search. :D
 
It's the little green arrow like a play button. Or you can press F5.

EDIT: Stupidly, the "Build" toolbar isn't turned on by default either (like, who would want to build anything with a compiler ;)). Right click on whitespace in the toolbar and select "Build" from the pop-up.
 
Err call me stupid but the arrow doesn't work unless i go to the menu Test->New Test->here i choose anything. Then i close all the zilion windows that apear. Then i reopen my old cpp file and then i can click on the green arrow. Which unfortunatley does the same thing. It simply says test passed.
I tried the build thing. Yes, it wasn't there. After i click build solution a window named Output apears and all it says is: ========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========.

Maybe i should've asked this before - but i didn't get an error so i thought it was ok. I'm using old C functions like printf,scanf same thing with the libraries. But i don't get any errors. Could this be it ?
 
No, C functions work fine. I have no idea why it says test passed however, sorry. Have you tried putting a breakpoint at the beginning of main and running it, then stepping through the code?

We use VS2005 at work so they may have done the usual thing and changed absolutely everything and moved everything they didn't change for VS2008 ;)
 
Debug > Start without debugging, or Ctrl-F5. However you'll still have the window popup and immediately close unless you add something to hold it open (eg, "system("pause");").

Well, i'm too lazy to learn somthing new.

Well, the problem when you're dealing with something 10+ years old is that you'll spend more time beating your head against the wall trying to get it to work than it would take to learn something new.

What's that allegro you're talking about.

Allegro

A 2D game programming library. For dealing with primitives (shapes) or actual 2D images/pictures. However it also provides tools for keyboard/mouse input, sound and etc.

Maybe i should've asked this before - but i didn't get an error so i thought it was ok. I'm using old C functions like printf,scanf same thing with the libraries. But i don't get any errors. Could this be it ?

If you're writing C++ programs, you should prefer C++ methods of doing things (cout + cin instead of printf + scanf, etc). However from a technical perspective they'll still work fine.
 
I love my sprintf and sscanf ;)

stringstream sucks and I don't like the format stuff in cin and cout much either. cout is good if you just want to use it for debugging though.
 
No, C functions work fine. I have no idea why it says test passed however, sorry. Have you tried putting a breakpoint at the beginning of main and running it, then stepping through the code?
Debug > Start without debugging, or Ctrl-F5. However you'll still have the window popup and immediately close unless you add something to hold it open (eg, "system("pause");").
There's gotta be something wrong. Maybe it needs a win restart. I'll try again tomorrow.

Well, the problem when you're dealing with something 10+ years old is that you'll spend more time beating your head against the wall trying to get it to work than it would take to learn something new.

Allegro

A 2D game programming library. For dealing with primitives (shapes) or actual 2D images/pictures. However it also provides tools for keyboard/mouse input, sound and etc.
I'll take a look at that tomorrow too.
 
Yea, still not working. But i have pics now:

This is before i do the New Test thing. As you can see, the green arrow is inactive, so is everything related to compile.


And this is after i create a test and run it. I see now that if i run it or compile it, it doesn't really do that to MY file. It only does it to the test file. (if i put errors in the code, it doesn't detect them).
 
Aha! You need to add your file to the solution...

First pic - you created a solution but no projects. Create a project (use new console app, empty project) then right click and add files to the project.

2nd pic - you are building the test project only, you haven't added your cpp file to the project. That will probably not compile because you would have main defined twice then.

EDIT: 2nd pic looks like it is an installer project (msi) so running it probably just does a dummy install...
 
OMFG - it worked. Hello world. Thanks ParadigmShifter :worship:

And i didn't even get to my main problem, the graphics. :lol: I'll start working on it now.
 
I'd recommend using an up to date graphcs library as well.

You might want to check out www.gamedev.net, that's a good site for programming questions.
 
And another problem occurs. Still not in the graphics part.

Code:
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <io.h>
using namespace std;

void main()
{
string init="F";
printf("%s", init);
getch();
}
The result of this is: <null> instead of F. (the crap-load of includes are for larger parts of the program).

P.S. - it works in borland5
 
You can't use a std::string as is in a printf. Use cout or else use

printf( "%s", init.c_str() );

EDIT: Also, output a newline so you flush stdout or else use fflush(stdout) before your getch. If you use cout use std::endl. (or cout.flush)

EDIT2: You can't pass a string to a function that wants a char* either, that's what the c_str method is for. Since printf takes a variable number of arguments it doesn't know you passed a dud one to it. (Some compilers check this however).
 
std::cout << init << "\n";

Yep - works fine now.

But what is the equivalent to fprintf ?

I have this thing:
Code:
FILE *lp = fopen("a.txt","w");
		fprintf(lp,"%s\n",init);
fclose(lp);
 
I think stringstream might do that. I don't like C++ style IO much so I'd have to look it up, and I'm not at work on a Sunday ;)

Or just use init.c_str() in the fprintf. That's what I'd do ;)

EDIT: Note, outputting a newline doesn't flush cout like it does with stdout, you want to use cout << std::endl; for that. Or use cerr which is unbuffered.
 
fprintf(lp,"%s",init.c_str());
Worked perfectly. :D (i didn't need the \n in the first place, the result string has to be in 1 line)
 
Top Bottom