我这儿有一段程序,为什么在TC里运行没问题在VC里会出问题

# include <graphics.h> # include <math.h> # include <dos.h># define pi 3.1415926 void draw(int a, int b, int c){ float x, y; x=a*cos(b*c*pi/180-pi/2)+300; /*确定横坐标*/ y=a*sin(b*c*pi/180-pi/2)+240; /*确定纵坐标*/ line(300, 240, x, y);/*绘制时针或分针或秒针*/}void init() /*划时钟边框函数*/ { int i,l,x1,x2,y1,y2; circle(300,240,200);/*以(300,240)为圆心,200为半径画圆*/ circle(300,240,5);/*以(300,240)为圆心,5为半径画圆*/ for(i=0;i<60;i++) /*划钟点上的短线*/ { if(i%5==0) l=15; else l=5; x1=200*sin(i*6*pi/180)+300; /*画线函数*/ y1=200*cos(i*6*pi/180)+240; x2=(200-l)*sin(i*6*pi/180)+300; y2=(200-l)*cos(i*6*pi/180)+240; line(x1,y1,x2,y2); } } main(){ int x, y,i; int gdriver, gmode; unsigned char h, m, s; struct time t[1]; gdriver = DETECT; initgraph(&gdriver, &gmode, ""); /*初始化*/ for(i=0;i<=6;i++) { outtextxy(300,80,"12") ; outtextxy(300,390,"6"); outtextxy(140,230,"9"); outtextxy(460,230,"3"); } init(); /*调用init()函数*/ setwritemode(1);/*将当前线与原有的线进行异或操作*/ gettime(t); /*将计算机时间写入结构体t中*/ h = t[0].ti_hour; /*h赋初值当前时数*/ m = t[0].ti_min; /*m赋初值当前分数*/ s = t[0].ti_sec; /*s赋初值当前秒数*/ setcolor(7); draw(150, h, 30); /*画时针*/ setcolor(14); draw(170, m, 6); /*画分针*/ setcolor(4); draw(190, s, 6); /*画秒针*/ while (!kbhit()) { while (t[0].ti_sec == s) gettime(t); setcolor(4); draw(190, s, 6); /*清除前面画的秒针*/ s = t[0].ti_sec; draw(190, s, 6); /*画秒针*/ if (t[0].ti_min != m) { setcolor(14); draw(170, m, 6); /*清除前面画的分针*/ m = t[0].ti_min; draw(170, m, 6); /*画分针*/ } if (t[0].ti_hour != h) { setcolor(7); draw(150, h, 30); /*清除前面画的时针*/ h = t[0].ti_hour; draw(150, h, 30); /*画时针*/ } } getch(); closegraph(); /*退出图形界面*/}运行后有一个错误,能帮我改一下吗?
2026年09月27日 01:59
有2个网友回答
网友(1):

这是兼容性问题。C语言的标准中不包含图形库,graphics.h不是C语言标准,因此使用了graphics.h中的函数的程序换一种编译器和运行环境之后不一定还能够被支持。
graphics.h中的图形函数都是建立在initgraph的基础之上的,而initgraph使用自己的图形驱动器,除了VC的原因之外,使用自己的显示驱动在Windows操作系统中也是不能允许的。
也就是说,不论从什么理由来说,在VC中是不能使用graphics.h中的函数的,只要使用必然出错。

VC本来就是面向GUI的,拥有Windows提供的强大的图形功能,根本没有必要使用graphics.h实现图形功能。

网友(2):

把运行后的错误贴出来,然后才能告诉你该怎么做。