-1

Eclipse 告诉我我有多个函数定义。我只是无法发现错误。这是我的 main.c

#include <stdio.h>
#include "kontaktverzeichnis.h"


int main(){

    kontakt_hinzufuegen();

    return 0;
}

这是标题:

#ifndef KONTAKTVERZEICHNIS_H_
#define KONTAKTVERZEICHNIS_H_
#include "kontaktfunktionen.c"

int kontakt_hinzufuegen();


#endif /* KONTAKTVERZEICHNIS_H_ */

这是 kontaktfunktionen.c

#include <stdio.h>

kontakt[];


kontakt_hinzufuegen(){
int i = 0;
printf("Bisher sind %i Kontakte angelegt.",kontakt[i]);

    kontakt[i++];

}

struct kontaktname{
    char* name;
    char* vorname;
};

struct kontaktanschrift{
    char* strasse;
    int hausnummer;
    int plz;
    char* ort;
    char* land;

};

我的错误在哪里?

4

3 回答 3

5

您不应该使用#includeC 文件,这不是组织代码的正确方法。

您应该分别编译 C 文件,然后将它们链接在一起,或者使用单个编译器调用一次编译它们。

于 2013-12-10T13:08:43.367 回答
1

你的错误是kontaktfunktionen.h你包括kontaktfunktionen.c. 这将包括kontaktfunktionen.c您使用时已声明的所有定义和声明kontaktfunktionen.c

正如其他人所说:您不应该在头文件中包含.c文件。

于 2013-12-10T13:08:36.520 回答
1

不要#include在你的头文件中做任何事情。并#include "kontaktverzeichnis.h"kontaktfunktionen.c文件中做一个。

正如@StoryTeller 评论的那样,在文件中定义你的kontakt_hinzufuegen()as并从函数中返回一个值,如 ex::int kontakt_hinzufuegen()kontaktfunktionen.cintkontakt_hinzufuegen

#include <stdio.h>
#include "kontaktverzeichnis.h"

// define the type for this array as below
int kontakt[];


int kontakt_hinzufuegen(){
 int i = 0;
 printf("Bisher sind %i Kontakte angelegt.",kontakt[i]);

 kontakt[i++];

 // Return an int value
 return 0 ;

}
于 2013-12-10T13:10:59.733 回答