Entwickler-Ecke

Off Topic - Kriege C-Programm nicht zum Laufen...


Jakob_Ullmann - Sa 12.03.11 20:22
Titel: Kriege C-Programm nicht zum Laufen...
Hey!

Ich stehe gerade irgendwie völlig auf dem Schlauch. Ich habe ein C-Programm, das aus folgenden Dateien besteht:

main.c

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
#include <stdio.h>
#include "main.h"

int main(int argc, char** argv)
{
  int i;
  
  for (i = 0; i <= 12; i++) {
    if (is_keywd(keywords[i]))
      printf("%s\n", keywords[i]);
  }
  
  return 0;
}


main.h

Quelltext
1:
2:
3:
4:
5:
6:
7:
#ifndef _MAIN_H_
#define _MAIN_H_

#include "bool.h"
#include "syntax.h"

#endif


bool.h

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
#ifndef _BOOL_H_
  #define _BOOL_H_
    /* Boolean type */
    #ifndef BOOL
      #define BOOL char
    #endif

    /* constants */
    #ifndef TRUE
      #define TRUE 1
    #endif

    #ifndef FALSE
      #define FALSE 0
    #endif

#endif


syntax.h

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
#ifndef _SYNTAX_H_
#define _SYNTAX_H_

#include "bool.h"

#define KEYS_LENGTH 13
#define KEYS_STR_LENGTH 10
char keywords[13][10] = {"begin", "end", "if",
   "then", "else", "case", "of", "for", "to", "do", "while",
   "repeat", "until"};

BOOL is_keywd(char *str);
BOOL is_int(char *str);
BOOL is_alpha(char *str);     

#endif


syntax.c

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "syntax.h"

BOOL is_keywd(char *str)
{
  short i;
  
  for (i = 0; i < KEYS_LENGTH; i++)
    if (!strcmp(str, keywords[i])) return TRUE;
  
  return FALSE;
}

BOOL is_int(char *str)
{
  short i;
  for (i = 0; i < strlen(str); i++)
    if ((str[i] < '0') || (str[i] > '9')) return FALSE;
  return TRUE;
}


Man sieht, es ist noch sehr überschaubar.

Einen echten Compiler-Fehler gibt es nicht, ich kriege nur vom Linker (sieht zumindest danach aus, da der angeblich mit Exit-Status 1 abbricht) eine Meldung:


Quelltext
1:
syntax.o:(.data+0x0): multiple definition of `keywords'                    


Jetzt weiß ich aber nicht, wie 'keywords' mehrmals in das Datensegment kommt. Sieht jemand spontan einen Fehler?

-- EDIT: Ich Depp!!! Manchmal wirkt eine kleine Änderung Wunder:

syntax.h

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
#ifndef _SYNTAX_H_
#define _SYNTAX_H_

#include "bool.h"

#define KEYS_LENGTH 13
#define KEYS_STR_LENGTH 10
extern char keywords[KEYS_LENGTH][KEYS_STR_LENGTH];

BOOL is_keywd(char *str);
BOOL is_int(char *str);
BOOL is_alpha(char *str);     

#endif


syntax.c

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "syntax.h"

char keywords[KEYS_LENGTH][KEYS_STR_LENGTH] = {"begin", "end", "if",
   "then", "else", "case", "of", "for", "to", "do", "while",
   "repeat", "until"};


BOOL is_keywd(char *str)
{
  short i;
  
  for (i = 0; i < KEYS_LENGTH; i++)
    if (!strcmp(str, keywords[i])) return TRUE;
  
  return FALSE;
}

BOOL is_int(char *str)
{
  short i;
  for (i = 0; i < strlen(str); i++)
    if ((str[i] < '0') || (str[i] > '9')) return FALSE;
  return TRUE;
}