First defined here

Gast #1969590
Lesenswert?

Ich habe es jetzt schon mit eclipse versucht der code::blocks, aber 
jedesmal wenn ich das Projekt bauen möchte kommen diese fehler:
1
Description  Resource  Path  Location  Type
2
first defined here  collatz.c  /test/src  line 6  C/C++ Problem
3
first defined here  collatz.c  /test/src  line 19  C/C++ Problem
4
first defined here  collatz.c  /test/src  line 26  C/C++ Problem
5
first defined here  eingabe.c  /test/src  line 3  C/C++ Problem
6
first defined here  eingabe.c  /test/src  line 42  C/C++ Problem
7
first defined here  eingabe.c  /test/src  line 53  C/C++ Problem
8
multiple definition of `collatz'  collatz.c  /test/src  line 6  C/C++ Problem
9
multiple definition of `collatzGerade'  collatz.c  /test/src  line 19  C/C++ Problem
10
multiple definition of `collatzUngerade'  collatz.c  /test/src  line 26  C/C++ Problem
11
multiple definition of `flushStd'  eingabe.c  /test/src  line 53  C/C++ Problem
12
multiple definition of `liesNatZahl'  eingabe.c  /test/src  line 3  C/C++ Problem
13
multiple definition of `schreibeNatZahl'  eingabe.c  /test/src  line 42  C/C++ Problem

und ich weiß einfach nicht was das soll = ((


eingabe.c
1
#include "eingabe.h"
2
unsigned int liesNatZahl(unsigned int min)
3
{
4
    unsigned int einlesen=0;
5
    int stimmt=0;
6

7
    while(stimmt ==0)
8
    {
9
        printf("\nBitte geben Sie eine positive Zahl n > %i ein: ", min);
10

11
        /*EINGABE NEGATIV*/
12
         if(scanf("-%u", &einlesen)==1)
13
        {
14
            printf("Bitte geben Sie keine negative Zahlen ein!");
15
            flushStd();
16
        }
17

18
        /*EINGABE KLEINER MIN*/
19
        else if(scanf("%u", &einlesen)==1 && einlesen <=min)
20
        {
21
            printf("Keine Zahl groeser %i eingegeben!", min);
22
            flushStd();
23
        }
24

25
        /*EINGABE ZEICHEN*/
26
        else if(getchar() != '\n')
27
        {
28
            printf("Bitte geben Sie keine Zeichen ein!");
29
            flushStd();
30
        }
31

32
        /*EINGABE STIMMT*/
33
        else
34
        {
35
            stimmt=1;
36
            return einlesen;
37
        }
38
    }
39
}
40

41
void schreibeNatZahl(unsigned int n)
42
{
43
    static int zahler=0;
44
    if(zahler%6==0)
45
    {
46
        printf("\n");
47
    }
48
    printf("%13u", n);
49
    zahler++;
50
}
51

52
void flushStd()
53
{
54
    while(getchar()!= '\n');
55
}

eingabe.h
1
#ifndef EINGABE_H_INCLUDED
2
#define EINGABE_H_INCLUDED
3
#include <stdio.h>
4
unsigned int liesNatZahl(unsigned int min);
5
void schreibeNatZahl(unsigned int n);
6
void flushStd();
7

8
#endif // EINGABE_H_INCLUDED

collatz.c
1
#include "collatz.h"
2
void collatzGerade(unsigned int n);
3
void collatzUngerade(unsigned int n);
4

5
void collatz(unsigned int c)
6
{
7
    if(c==1);
8
    else if((c%2)==0)
9
    {
10
        collatzGerade(c);
11
    }
12
    else if ((c%2)==1)
13
    {
14
        collatzUngerade(c);
15
    }
16

17
}
18
void collatzGerade(unsigned int n)
19
{
20
    n = n / 2 ;
21
    schreibeNatZahl(n);
22
    collatz(n);
23
}
24

25
void collatzUngerade(unsigned int n)
26
{
27
    n = 3 * n + 1;
28
    schreibeNatZahl(n);
29
    collatz(n);
30
}

collatz.h
1
#ifndef COLLATZ_H_INCLUDED
2
#define COLLATZ_H_INCLUDED
3
#include <stdio.h>
4
void collatz(unsigned int c);
5
#endif // COLLATZ_H_INCLUDED

main.c
1
#include "eingabe.c"
2
#include "collatz.c"
3

4
int main()
5
{
6
    collatz(liesNatZahl(15));
7
    return 0;
8
}
Moderator #1969614
Lesenswert?

Ersetze die Zeilen
1
#include "eingabe.c"
2
#include "collatz.c"
durch
1
#include "eingabe.h"
2
#include "collatz.h"

.c-Dateien werden normalerweise nicht includet, sondern getrennt
kompiliert. In deinem Projekt wird offensichtlich beides getan, deswegen
bekomst du die Doppeltgemoppeltmeldungen.
Gast #1969641
Lesenswert?

wow vielen Dank!
Die Fehler sind weg!

Jetzt habe ich noch 2 Warnungen die ich mir nicht erklären kann:
1
Description  Resource  Path  Location  Type
2
control reaches end of non-void function  eingabe.c  /test/src  line 39  C/C++ Problem
3
implicit declaration of function 'schreibeNatZahl'  collatz.c  /test/src  line 21  C/C++ Problem

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren