C语言 无法运行 c 图形程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2513133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 04:56:37  来源:igfitidea点击:

Cannot run c graphics programs

cturbo-c

提问by PrithviRaj

I have developed a graphic program on a desktop system. But when I tried to run it on the hp compaq laptop it's not getting executed. I developed it using Turbo C. Then i tried writing a simple graphic program in Turbo C on the laptop, but the problem I am getting is in 'initgraph' statement it is unable to detect the driver.

我在桌面系统上开发了一个图形程序。但是当我尝试在 hp compaq 笔记本电脑上运行它时,它没有被执行。我使用 Turbo C 开发它。然后我尝试在笔记本电脑上用 Turbo C 编写一个简单的图形程序,但我遇到的问题是在“initgraph”语句中它无法检测到驱动程序。

Can you please tell me what might be the problem?

你能告诉我可能是什么问题吗?

回答by abelenky

Turbo-C, much like my first girlfriend, will always have a special place in my heart.

Turbo-C,就像我的第一个女朋友一样,在我心中永远占有特殊的位置。

But its time to let her go. She's not the same girl you remember, and just cannot keep up with modern times. She may have been hip and cool at the time, but she can't handle modern trends at all. Even 32-bit memory is a real challenge for her. You're a better man now, and deserve a real woman. Go find yourself a good Visual Studio, or a nice GCC environment.

但是是时候让她离开了。她不是你记忆中的那个女孩,只是跟不上现代。她当时可能时髦又酷,但她根本无法驾驭现代潮流。即使是 32 位内存对她来说也是一个真正的挑战。你现在是一个更好的男人,值得一个真正的女人。去给自己找一个好的 Visual Studio,或者一个好的 GCC 环境。

I'm not saying you have to forget Turbo-C. I know she was your first and will always be magical, but put her pictures in a shoebox, and don't take them out more than once a year. Its time to move on, buddy.

我并不是说你必须忘记 Turbo-C。我知道她是你的第一个,而且永远是神奇的,但把她的照片放在鞋盒里,一年不要拿出超过一次。是时候继续前进了,伙计。

回答by Gabe

It sounds like it can't detect what kind of graphics card you have. Try setting the graphdriverparameter to either VGAor IBM8514.

听起来它无法检测您拥有哪种类型的显卡。尝试将graphdriver参数设置为VGAIBM8514

回答by Saffhire

In Turbo c goto options->Linker->Liabraries-> add Graphics Library. It might help

在 Turbo c 中转到选项->链接器->库-> 添加图形库。它可能有帮助

回答by Theja

I'm assuming that all the other prerequisites like linkersare satisfied.

我假设所有其他先决条件如链接器都得到满足。

Now, as we know the BGI folder is usually in the following path(i.e. if you've followed the default installation):

现在,我们知道 BGI 文件夹通常位于以下路径中(即,如果您遵循默认安装):

C:\TurboC++\disk\TurboC3\BGI

C:\TurboC++\磁盘\TurboC3\BGI

As you can see the BGI folder is inside "TurboC3" and not TC. So the code you need to put in your program is as follows,

如您所见,BGI 文件夹位于“TurboC3”内,而不是 TC。所以你需要在你的程序中放入的代码如下,

initgraph(&gd, &gm, "C:\TurboC3\BGI");

I hope this helps :) Happy graphics programming :D

我希望这会有所帮助 :) 快乐的图形编程 :D

回答by Arun Kumar

The first step in any graphics program is to initialize the graphics drivers on the computer using initgraph method of graphics.h library.

任何图形程序的第一步都是使用 graphics.h 库的 initgraph 方法初始化计算机上的图形驱动程序。

void initgraph(int *graphicsDriver, int *graphicsMode, char *driverDirectoryPath);

It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode. driverDirectoryPath : It specifies the directory path where graphics driver files (BGI files) are located. If directory path is not provided, then it will seach for driver files in current working directory directory. Sample initialization statement

它通过加载传递的图形驱动程序然后将系统更改为图形模式来初始化图形系统。driverDirectoryPath :指定图形驱动文件(BGI文件)所在的目录路径。如果未提供目录路径,则它将在当前工作目录目录中搜索驱动程序文件。示例初始化语句

initgraph(&gd, &gm, "C:\TC\BGI");

Here is a list of C graphics program for reference :http://www.techcrashcourse.com/2015/08/c-graphics-programming-tutorial.html

以下是 C 图形程序列表供参考:http: //www.techcrashcourse.com/2015/08/c-graphics-programming-tutorial.html

Additionally, you can try using DOSBOX to run C graphics programs in Windows OS. I tried DOSBOX and it works smoothly in Windows. Here is one C graphics program which I tried using DOS Box http://www.techcrashcourse.com/2015/08/c-program-bouncing-ball-animation-graphics.html

此外,您可以尝试使用 DOSBOX 在 Windows 操作系统中运行 C 图形程序。我尝试了 DOSBOX,它在 Windows 中运行流畅。这是我尝试使用 DOS Box http://www.techcrashcourse.com/2015/08/c-program-bouncing-ball-animation-graphics.html 的一个 C 图形程序

回答by Deepak Thakur

you need to initialize the graphics function first. below is the code to initialize.

您需要先初始化图形功能。下面是初始化的代码。

int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc\\bgi");

int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc\\bgi");

this will initialize the graphics.

这将初始化图形。

回答by Kapil Kumar

The Steps to make your TC able to run graphics program are as follows:

使您的 TC 能够运行图形程序的步骤如下:

  1. copy CGA.BGI and EGAVGA.BGI files from TC\BGI folder and paste them in TC\BIN directory.

  2. Open TC by clicking on TC\BIN\TC.EXE.

  3. Click on Options -> Linker -> Libraries .

  4. Select the Graphics Library option and Press OK.

  5. Now you can compile your graphics program with Zero Compilation Errors.

  1. 从 TC\BGI 文件夹中复制 CGA.BGI 和 EGAVGA.BGI 文件并将它们粘贴到 TC\BIN 目录中。

  2. 单击 TC\BIN\TC.EXE 打开 TC。

  3. 单击选项 -> 链接器 -> 库。

  4. 选择图形库选项并按确定。

  5. 现在,您可以使用零编译错误来编译图形程序。

Thanks!

谢谢!