Multiple de la même erreur lors de la compilation du “jeton” d’erreur “: attendu”) avant “*”

J’essaye de programmer en C.

Quand je comstack avec les arguments suivants ….

gcc -D_BSD_SOURCE -Wall -ansi -pedantic -g tokenizer.c FileOccur.c WordList.c wordstat.c indexer.c -o indexer 

Je reçois ceci du terminal en réponse:

 In file included from ../Headers/WordList.h:11, from FileOccur.c:12: ../Headers/FileOccur.h:18: error: expected ')' before '*' token ../Headers/FileOccur.h:20: error: expected ')' before '*' token In file included from ../Headers/WordList.h:11, from WordList.c:11: ../Headers/FileOccur.h:18: error: expected ')' before '*' token ../Headers/FileOccur.h:20: error: expected ')' before '*' token WordList.c: In function 'insert_List': WordList.c:155: warning: implicit declaration of function 'insert_FileOccur' In file included from ../Headers/WordList.h:11, from wordstat.c:11: ../Headers/FileOccur.h:18: error: expected ')' before '*' token ../Headers/FileOccur.h:20: error: expected ')' before '*' token In file included from ../Headers/WordList.h:11, from indexer.c:11: ../Headers/FileOccur.h:18: error: expected ')' before '*' token ../Headers/FileOccur.h:20: error: expected ')' before '*' token 

Voici mon fichier FileOccur.h:

 /* * FileOccur.h * Includes list of all functions declared in FileOccur.c so that other source files * can use them. Also defines the fields for the structs used for FileOccur.c */ #ifndef FILEOCCUR_H #define FILEOCCUR_H #include "../Headers/WordList.h" #include  #include  typedef struct FileOccur FileOccur; FileOccur * create_FileOccur(char * fileName); void fprint_FileOccur(FILE * indexFile, FileOccur * currFileOccur); void free_Occur(FileOccur * curr); int insert_FileOccur(word * lCurr,char * fileName); void print_FileOccur(FileOccur * currFileOccur); int sort_TotalOccur(word * lCurr, FileOccur * prevFile, FileOccur * currFile); struct FileOccur{ /* * the FileOccur struct is used as a node to keep information about how many times an * an item was found in a file, the file's name and the next file that has the same * item in it, in this case a word * */ char * fileName; int occur; FileOccur * next; }; #endif 

et voici mon fichier WordList.h:

 /* * WordList.h * Includes list of all functions declared in WordList.c so that other source files * can use them. Also defines the fields for the structs used for WordList.c */ #ifndef WORDLIST_H #define WORDLIST_H #include  #include  #include "FileOccur.h" typedef struct word word; typedef struct wordList list; word * create_Word(char * spell, char * fileName); void fprint_List(FILE * indexFile, list * words); void free_List(list * words); int insert_List(char * currSsortingng, list * words, char * fileName); void print_List(list * words); struct word{ /* the word struct used as a node to keep important information about each word including * its occurences in the various files, the next word in the list, and the spelling of the * current word. */ char * spell; struct word * next; FileOccur * totalOccur; }; struct wordList{ /* my linked list that simply has a pointer to the first node*/ word * start; }; #endif 

S’il vous plaît laissez-moi savoir si vous avez besoin de plus d’informations, merci!

Vos fichiers d’en-tête s’incluent de manière circulaire. C’est la raison de votre erreur.

Ne tentez jamais l’inclusion circulaire. Cela n’apporte rien et ne peut que conduire à des erreurs. Redéfinissez vos en-têtes dans une hiérarchie “stratifiée”: les en-têtes de niveau supérieur incluent les en-têtes de niveau inférieur, mais pas l’inverse.

Dans votre cas, l’inclusion circulaire peut être éliminée de l’une des deux manières suivantes:

  1. Arrêtez d’inclure WordList.h dans FileOccur.h . À la place, fournir une déclaration

     typedef struct word word; 

    dans FileOccur.h .

  2. Arrêtez d’inclure FileOccur.h dans WordList.h . À la place, fournir une déclaration

     typedef struct FileOccur FileOccur; 

    dans WordList.h .

La meilleure approche dépend du fichier d’en-tête que vous considérez comme étant un fichier de niveau supérieur.

Voir également ici Éviter les dépendances circulaires des fichiers d’en-tête.