fle*_*can 0 c compilation linked-list list
所以我现在已经有一段时间了,似乎无法找到问题,甚至我的老师也找不到.
所以我有这个头文件:
#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;
Run Code Online (Sandbox Code Playgroud)
在我包含此标头的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;
}
Run Code Online (Sandbox Code Playgroud)
因此,当我编译时发生此错误:list.h | 6 | error:在'*'标记之前预期'=',',',';','asm'或' attribute '
我已经搜索了一些关于这个错误的错误,但似乎找不到一个可以帮助我的错误.
请帮忙 :)
Mic*_*urr 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);
Run Code Online (Sandbox Code Playgroud)
将结构定义移到头文件中使用的位置上方:
#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);
Run Code Online (Sandbox Code Playgroud)
你必须在使用它之前定义它.
wordData * search_in_list(int iWordID, struct wordData **prev);
^
|
This is also incorrect. Should be "wordData **prev"
That's what the typedef is for.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |