折れ線グラフを描画するためのスケール用に、language と graphics.h を使用してコードを記述しようとしていますが、次のようになります。
そして私はこれを得る:
xGraphics2Screen(double)' の複数定義... ld は 1 つの終了ステータスを返しました
InitGraphics(char*)' first defined here
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;
}