关于一个图形编程
莱鸟学图形编程!以上想运行下面的程序:
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
#include <bios.h>
#include <ctype.h>
#include <process.h>
#include <conio.h>
#include <system.h>
#define COLOR WHITE
#define F1 59
#define F2 60
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define HOME 71
#define END 79
#define PAGEUP 73
#define PAGEDOWN 81
void menu(void);
void save(void);
void load(void);
void xhaira(int a,int b);
struct k
{
char c[2];
int i;
};
typedef struct k KEY;
KEY key;
struct dot
{
int x;
int y;
};
typedef struct dot DOT;
DOT dis;
main()
{
int inc = 1, k, j, m, r;
int driver, mode;
DOT firstdot, secdot;
dis.x = 200;
dis.y = 200;
driver = DETECT;
mode = VGAHI;
initgraph(&driver, &mode, "C:\\TC\\BGI");
setbkcolor(BLUE);
cleardevice();
setcolor(YELLOW);
xhairs(dis.x, dis.y);
while( key.c[0] != 'q')
{
menu();
key.i = bioskey(0);
xhairs(dis.x, dis.y);
if(!key.c[0])
{
switch( key.c[1] )
{
case LEFT: dis.x -= inc;
break;
case RIGHT: dis.x += inc;
break;
case UP: dis.y -= inc;
break;
case DOWN: dis.y += inc;
break;
case HOME: dis.x -= inc;
dis.y -= inc;
break;
case PAGEUP:dis.x += inc;
dis.y -= inc;
break;
case END: dis.x -= inc;
dis.y += inc;
break;
case PAGEDOWN: dis.x += inc;
dis.y += inc;
break;
case F1: inc = 1;
break;
case F2: inc = 5;
break;
}
}
else
{
switch(tolower(key.c[0]))
{
case 'a': putpixel (dis.x,dis.y,COLOR);
firstdot.x = dis.x;
firstdot.y = dis.y;
break;
case 'b': putpixel (dis.x,dis.y,COLOR);
secdot.x = dis.x;
secdot.y = dis.y;
break;
case 'l': line(firstdot.x,firstdot.y,
secdot.x,secdot.y);
break;
case 'o': r = sqrt(fabs((secdot.x - firstdot.x)*(
secdot.x - firstdot.x)+(
secdot.y - firstdot.y)*(
secdot.y - firstdot.y)));
circle(firstdot.x,firstdot.y,r);
break;
case 'h': rectangle(firstdot.x,firstdot.y,
secdot.x,secdot.y);
break;
case 'c': cleardevice();
break;
case 'w': save();
break;
case 'r': load();
break;
}
xhairs(dis.x,dis.y);
}
}
closegraph();
}
void xhairs(int a,int b)
{
int i;
for(i = a-5; i <= a+5; i++)
putpixel(i,b,15 ^ getpixel(i,b));
for(i = b-5; i <= b+5; i++)
putpiexl(a,i,15 ^ getpixel(a,i));
}
void menu(void)
{
#define STARTX 10
#define STARTY 22
#define DISTANCE 30
int i;
char *menu_name[] = { "a:start point.", "b:end point.",
"l:draw line.","o:draw circle.",
"h:draw box.","c:clear screen.",
"F1:step = 1.","F2:step = 5",
" Home pageUP"," End PageDown.",
"w:save graph","r:load graph",
"q:quit" };
setcolor( WHITE );
rectangle(5,5,150,470);
rectangle(155,5,635,470);
setcolor( LIGHTBLUE );
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
outtextxy(36,STARTY,"menu");
setcolor( YELLOW );
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
for(i = 0;i <= 14; i++)
outtextxy(STARTX, STARTY+(i+1)*DISTANCE,menu_name[i]);
}
void save(void)
{
int i, j;
FILE *fp;
if((fp = fopen("graph.dat","w+")) == NULL)
{
printf("cannot open this file!");
exit(0);
}
for(i = 5; i <= 470; i++)
{
for(j = 155; j <= 635; j++)
{
fputc( getpiel (j,i), fp );
}
}
fclose(fp);
outtextxy(260,471,"save over!");
}
void load(void)
{
int i, j;
FILE *fp;
if((fp = fopen("greph.dat","r+")) == NULL)
{
printf("cannot open this file!");
exit(0);
}
outtextxy(280,471,"loading... ...");
for(i = 5; i <= 470; i++)
{
for(j = 155; j <= 635; j++)
putpixel( j,i,fgetc(fp) );
}
fclose(fp);
outtextxy(368,471,"over");
}
但结果tc编译器指出:
Undefined symbol '_getpiel' in module 2.c;与
Undefined symbol '_putpiexl' in module 2.c!
这俩个问题,于是上网找到是却了一个头文件:system.h!
但tc目录include中并没有此文件!
这里想问问对图形编程有经验的高手,有没有遇到此类问题!
应该怎样解决呢?