1

我正在尝试使用语言和 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;   
}
4

2 回答 2

1

graphics.h已经包含一个名为InitGraphics()的函数。您需要更改函数的名称。

于 2013-03-09T18:15:42.407 回答
1
int InitGraphics( char * pszBgiPath )

重命名该函数,因为它已经在 graphics.h 中

于 2013-03-09T18:19:39.603 回答