0

だから私はかなり長い間これに取り組んできましたが、問題を見つけることができないようです.私の先生でさえそれを見つけることができませんでした.

だから私はこのヘッダーファイルを持っています:

    #include <stdio.h>
    #include <stdbool.h>

    void print_list(void);
    int delete_from_list(int iWordID);
    wordData * create_list(int iWordID, char * cWord);
    wordData * add_to_list(int iWordID, char * cWord, bool add_to_end);
    wordData * search_in_list(int iWordID, struct wordData **prev);
    void print_list(void);

    typedef struct _wordData
    {
    int iWordID;
    char * cWord;
    struct _wordData *next;

    } wordData;

そして、このヘッダーをインクルードする C ファイルには、次の関数があります。

    wordData* create_list(int iWordID, char * cWord)
    {
     //printf(cWord);

    printf("\n creating list with headnode as [%d] %s\n",iWordID,cWord);
    wordData *ptr = (struct wordData*)malloc(sizeof(struct wordData));
    if(NULL == ptr)
    {
    printf("\n Node creation failed \n");
    return NULL;
    }

    ptr->iWordID = iWordID;

    //char * temp = (char*)malloc(sizeof(cWord));
    ptr -> cWord = cWord;


    ptr->next = NULL;

    head = curr = ptr;
    return ptr;
    }

したがって、コンパイルすると次のエラーが発生します: list.h|6|error: expected '=', ',', ';', 'asm' or ' attribute ' before '*' token|

このエラーでかなりの数の awners を検索しましたが、私を助けるものを見つけることができないようです。

助けてください :)

4

4 に答える 4

14

wordData struct定義をヘッダーの先頭に移動します。プロトタイプで使用する前に定義する必要があります (または、前方宣言する必要があります)。

#include <stdio.h>
#include <stdbool.h>

typedef struct _wordData
{
int iWordID;
char * cWord;
struct _wordData *next;

} wordData;

void print_list(void);
int delete_from_list(int iWordID);
wordData * create_list(int iWordID, char * cWord);
wordData * add_to_list(int iWordID, char * cWord, bool add_to_end);
wordData * search_in_list(int iWordID, struct wordData **prev);
void print_list(void);
于 2012-11-28T15:18:38.220 に答える
8

ヘッダー ファイルで使用されている場所の上に構造体定義を移動します。

#include <stdio.h>
#include <stdbool.h>

typedef struct _wordData
{
int iWordID;
char * cWord;
struct _wordData *next;

} wordData;

void print_list(void);
int delete_from_list(int iWordID);
wordData * create_list(int iWordID, char * cWord);
wordData * add_to_list(int iWordID, char * cWord, bool add_to_end);
wordData * search_in_list(int iWordID, struct wordData **prev);
void print_list(void);

使用する前に定義する必要があります。

wordData * search_in_list(int iWordID, struct wordData **prev);
                                             ^
                                             |
                             This is also incorrect. Should be "wordData **prev"
                              That's what the typedef is for. 
于 2012-11-28T15:19:16.100 に答える
1

使用しているポイントの前に構造体の定義を移動することとは別に、必要な別の変更があります。

にtypedefedstruct _wordDataしましたwordData

したがって、struct _wordDataまたはを使用しますが、存在しないwordDataものを使用しています。struct wordData

于 2012-11-28T15:23:18.907 に答える
1

コードに 2 つの独立したエラーがあります。

まず、使用する前wordDataに typedef-nameを定義する必要があります。

第二に、search_in_list宣言ではstruct wordData型を参照します。struct wordDataあなたのプログラムのようなタイプはまったくありません。あなたはstruct _wordData代わりに持っています。次に、2 番目のエラーが C ファイル (mallocなど) で繰り返されます。

于 2012-11-28T15:24:44.240 に答える