我尝试用语言和graphics.h编写一些代码用于扩展 绘制折线图但是:
我明白了:
InitGraphics(char*)' first defined here
xGraphics2Screen(double)'的多重定义 ... ld返回1退出状态
multiple definition of
我不知道会发生什么?
你能帮忙吗?
代码:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "tri.h"
#include<time.h>
#include<graphics.h>
typedef struct {
int key;
unsigned long value;
}Map;
static double s_xGraphicsMin;
static double s_yGraphicsMin;
static double s_xGraphicsMax;
static double s_yGraphicsMax;
static int s_xScreenMax, s_yScreenMax;
int InitGraphics( char * pszBgiPath )
{
int gdriver = DETECT, gmode, errorcode;
// Recherche le meilleur mode possible
initgraph(&gdriver, &gmode, pszBgiPath);
// Verifie que ca marche
errorcode = graphresult();
if (errorcode != grOk)
{
// Probleme !
return -1;
}
// Recupere la taille de l'ecran en pixels
// Sauvegarde dans des globales
s_xScreenMax = getmaxx();
s_yScreenMax = getmaxy();
return 0;
}
int yGraphics2Screen( double yGraphic )
{
int yScreen;
yScreen = (int)(s_yScreenMax -
s_yScreenMax *
(double)(yGraphic - s_yGraphicsMin) /
(double)(s_yGraphicsMax - s_yGraphicsMin));
return yScreen;
}
int xGraphics2Screen( double xGraphic )
{
int xScreen;
xScreen = (int)(s_xScreenMax *
(double)(xGraphic - s_xGraphicsMin) /
(double)(s_xGraphicsMax - s_xGraphicsMin));
return xScreen;
}
void DrawGraphicsAxys( int color, double xPas, double yPas,char * pszxTitle, char * pszyTitle )
{
int xScreenCenter, yScreenCenter;
double x,y;
char sz[25];
// Couleur
setcolor(color);
// Dessine l'axe des X
yScreenCenter = yGraphics2Screen(0);
line( 0, yScreenCenter, s_xScreenMax, yScreenCenter );
// Dessine l'echelle des X au pas xPas
for( x = s_xGraphicsMin; x < s_xGraphicsMax; x += xPas )
{
double xArrondi;
int xScreen;
// On dessine
xArrondi = x - fmod(x,xPas);
if( xArrondi != 0 )
{
xScreen = xGraphics2Screen(xArrondi);
line( xScreen, yScreenCenter - 2,
xScreen, yScreenCenter + 2 );
sprintf( sz, "%5.2f", xArrondi );
outtextxy(xScreen - 5, yScreenCenter + 6, sz );
}
}
// Dessine l'axe des Y
xScreenCenter = xGraphics2Screen(0);
line( xScreenCenter, 0, xScreenCenter, s_yScreenMax );
// Titre en X
if( pszxTitle )
outtextxy(s_xScreenMax - s_xScreenMax/3, yScreenCenter + 20, pszxTitle );
// Dessine l'echelle des Y au pas yPas
for( y = s_yGraphicsMin; y < s_yGraphicsMax; y += yPas )
{
double yArrondi;
int yScreen;
// On dessine
yArrondi = y - fmod(y,yPas);
if( yArrondi != 0 )
{
yScreen = yGraphics2Screen(yArrondi);
line( xScreenCenter - 2, yScreen,
xScreenCenter + 2, yScreen );
sprintf( sz, "%5.2f", yArrondi );
outtextxy(xScreenCenter + 6, yScreen, sz );
}
}
// Titre en Y
if( pszyTitle )
outtextxy( xScreenCenter + 15, 10, pszyTitle );
}
int main()
{
system("pause");
return 0;
}
答案 0 :(得分:1)
graphics.h 已经包含一个名为 InitGraphics()的函数。您需要更改 功能的名称。
答案 1 :(得分:1)
int InitGraphics( char * pszBgiPath )
重新编写函数,因为它已经在graphics.h中了。
答案 2 :(得分:0)
有一个头文件和一个用于图形的功能。您需要重命名该功能。并且,如果您在Code :: Blocks中尝试源代码,则可以遵循此procedure。