首页 > 解决方案 > 如何修复“对 createList 的未定义引用”

问题描述

我正在编写一个程序,用户可以创建单链表并将学生信息输入到列表中,但是我收到一条错误消息,提示“未定义对 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;
}

'''

标签: cdata-structuressingly-linked-list

解决方案


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

宣言:

struct node *createList(void);

定义:

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

推荐阅读