从另一个文件调用函数

时间:2014-01-05 16:43:35

标签: c

我需要在文件DB.c和ListOfCity.c中切换文件Dist.c中的函数,但是VS 2010给出了错误:
错误C2143:语法错误:缺少';'在'类型'之前。 (在每种情况下都在线)

当我将项目编译为C ++(而不是C,但我需要C而不是C ++)时,我可以运行已编译的exe文件,但是当我输入数字1或2时,它只显示“按任意键继续”。并且不要运行该功能。提前谢谢!

文件Dist.c

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <crtdbg.h>
#include "db.h"

#define _CRTDBG_MAP_ALLOC

int main(int argc, char** argv) {
    int choice;
    do {
        printf("[1] Index of city\n[2] Add city to end some next\Your choice: ");
        scanf("%d", &choice);
        switch(choice){
            case 1:
                void PrintCity();
        system("pause");
        break;
            case 2:
                AddOnEnd();
        system("pause");
        break;

            ..... 

            default:
                printf("Another numer.\n");
        system("pause");
        break;

        break;
        }
    } while (volba != 0);

文件DB.h

#include "ListOfCity.h"
typedef struct Database {
    int numberOfCity;
    tListOfCity* list;
    double **distances;
} tDatabase;

tDatabase *LoadDatabase(char* file);
void DeleteDatabase(tDatabase* db);
int GiveIndexCity(tDatabase* db, char* city);
double GiveDistanceBetweenCities(tDatabase* db ,char* city1, char* city2);
double CountDistance(tDatabase* db, tListOfCity* list);
void PrintDistance(tDatabaze* db, tListOfCity* list);

文件ListOfCity.h

#define LENGTH 60

typedef struct ListOfCity {
    char city[LENGTH];
    struct ListOfCity* next;
} tListOfCity;

tListOfCity* CreateCity(char* city);
tListOfCity *AddOnEnd(tListOfCity* list, tListOfCity* new);
void PrintCity(tListOfCity* list);

1 个答案:

答案 0 :(得分:2)

您的AddOnEnd()声明需要2个参数:

tListOfCity *AddOnEnd(tListOfCity* list, tListOfCity* new);

但你的函数调用没有通过任何???

AddOnEnd();

此外,

void PrintCity();

声明一个函数,它不调用函数。