如何修复“对createList的未定义引用”

时间:2019-05-03 02:02:18

标签: c data-structures singly-linked-list

我正在编写一个程序,用户可以创建一个单链列表并将学生信息输入到列表中,但是却收到一条错误消息,提示“对createList的引用未定义”,我该如何解决此错误? >

'''

struct student
{
    int id, age, choice;
    char name[30];
};

struct node
{
    struct student student_data;
    struct node *next;
};

struct node *prependNode(struct node *head);
/*void removeNextNode(struct node *node);*/

struct node *createList(void);

int main(void)
{
    struct node *head = NULL;
    int choice;

    printf("Please select an option: ");
    printf("1. Create\n");
/*      printf("2. Display\n");
    printf("3. Insert\n");
    printf("4. Remove\n");
    printf("5. Search");
    printf("6. Exist");*/
    scanf("%d", &choice);

switch(choice)
{
    case 1:
        head = createList();
        break;
}

return 0;
}

'''

1 个答案:

答案 0 :(得分:2)

您已经声明了函数createList,但实际上并未在任何地方定义它。您需要定义函数,或告诉编译器/链接器定义该文件/库的位置。

声明:

struct node *createList(void);

定义:

struct node *createList(void)
{
    // implementation here
}