Hi!, I'm newbie here on daniweb.. and i dont know if i'm in a right place to post this problem. lol. *sorry for my english*
anyway, will you please help me about Turbo C? My teacher gve us a sample problem and he starts it with this code :

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
int gd,gm;
void main()
{
gd=DETECT;
initgraph(gd,gm,"");
if(graphresult()!=grOk){exit(1);}

rectangle(0,0,getmaxx(),getmaxy());
rectangle(1,1,getmaxx()-1,getmaxy()-1);
settextstyle(1,0,1);
outtextxy(50,50,"HELLO");
circle(400,600,10);
getch();
closegraph();
}

and when I tried to run it, it suddenly closed. and I don't know what is wrong with this. :'( help me! did I missed some codes to put on or any misspelled codes? pls check it and tell me what is the right code for this. (^_^)

and another one, my teacher wants us to make/draw us a "computer set (monitor,cpu,keyboard)" using turbo C. and i dont have any idea how to start with it. Do you have any codes for this problem? pls help me. :'(

thank you so much!

Recommended Answers

All 12 Replies

>>when I tried to run it, it suddenly closed

That's because there is nothing at the end of main() to prevent that behavior. If you want it to stay open so that you can see it, then add getche(); at the end of main(). The program will then stop until you hit a key.

>will you please help me about Turbo C?

Turbo C/C++ is a real real old, and an ancient compiler!

Yes we know, but I think his school requires it. :@

>>when I tried to run it, it suddenly closed

That's because there is nothing at the end of main() to prevent that behavior. If you want it to stay open so that you can see it, then add getche(); at the end of main(). The program will then stop until you hit a key.

Dragonmeister!?!?! getche() ?!?!? getchar() please. It's at least standard...

Dragonmeister!?!?! getche() ?!?!? getchar() please. It's at least standard...

There is very little about Turbo C that is standard, so it doesn't make any difference whether he uses getche() or not. Could also do this without a problem

while( !kbhit() )
    delay(100);

That's not standard either, but works in that old crappy compiler.

commented: Couldn't agree more. Wish, could +rep > 1 :) +1

I have not programmed much on Turbo C, specially graphics.. But I have a couple of observations. I am 100% sure if these are indeed correct ... Please correct me if I am wrong

>>when I tried to run it, it suddenly closed

That's because there is nothing at the end of main() to prevent that behavior. If you want it to stay open so that you can see it, then add getche(); at the end of main(). The program will then stop until you hit a key.

He has a getch() on line 17. All the display functions are before that. So I think if all the functions are called correctly he should be able to see the output

Secondly

and when I tried to run it, it suddenly closed. and I don't know what is wrong with this. :

From this information I infer that he had a run time fault. Similar to the seg fault in the linux environment

>>when I tried to run it, it suddenly closed

That's because there is nothing at the end of main() to prevent that behavior. If you want it to stay open so that you can see it, then add getche(); at the end of main(). The program will then stop until you hit a key.

i tried it but still. :'(

I'm guessing that initgraph() fails there and the program just silently exits (i.e. calls exit(1)).

[EDIT]
After looking up initgraph() it's clear that the teacher gave you a bad example (perhaps intentionally?). Anyway, you have to change the call to initgraph() so that it matches the function's signature.

ya ..i am agree with mitrmkar .so you have to right the code for initgraph.
and it's right code will be

initgraph(&gd,&gm,"");

Hi all,

i have a douby that on the line number 9.That is we have to mention the path of graphics folder located in harddisk.means in line 9 ,between the quotemarks we should have to mention the graphics location.Like

if(graphresult()!=grOk){[B]exit(1)[/B];}

This is the cause. graphresult() fails.
P.S. @OP: How come nobody before noticed it? Because the formatting was bad. Format your code nicely & bugs will come out faster. :)

A great deal of what you want is included in Turbo C's help files.

After starting up the IDE (the editor inside Turbo C), click on "Help" on the far right hand side, and then on "Index".

One graphic function that you will certainly want to look at is "rectangle" (just start typing it and the help window will take you to it), and maybe "line", and possibly "setcolor", etc.

Along with a full explanation of these functions, it also has a complete sample program you can study and copy and paste, as well.

The above description is for Turbo C/C++ 1.01. Later versions may vary.

Regarding your previous problem - never have your program quit due to an error, without first printing out what the error was. Really elementary stuff like that, will save you a TON of time, in debugging.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.