简体   繁体   中英

How do i fix this error? warning: implicit declaration of function ‘main_menu’

this is a b-day reminder code utilizing linkedlists

typedef struct node  
{  
    char name[61];  
    int month;          int day;  
    int year;  
    struct node *next;  
}node;  

this is the list

typedef struct list  
{  
    node *head;  
    node *tail;  
}list;  

this is the create list code

list *create_list(list *plist)  
{  
    plist->head = NULL;  
    plist->tail = NULL;  
    return plist;  
}  

this inserts the node created to the list

list *insert_list(list *plist, node *pnode, node *new_node)  
{  
    new_node->next = pnode->next;  
    pnode->next = new_node;  
    if (plist->tail == pnode)  
    {  
            plist->tail = new_node;  
    }  
}  

this is the add birthday menu

void add_birthday(list *List)  
{  
    char x;  
    node *data = (node *) malloc(sizeof(node));  
    List = (list*) malloc(sizeof(list));  
    printf("******************************************************************\n");  
    printf("                    ADD BIRTHDAY REMINDER FORM\n");  
    printf("******************************************************************\n");  
    List = insert_list(List, data, create_node(data));  
    printf("Would you like to add another(y/n)?\n");  
    scanf("%c", &x);  
    if (x=='y')  
    {  
            while (x=='y')  
            {  
                    if (x=='y')  
                    {  
                            getchar();  
                            printf("******************************************************************\n");  
                            node *data = (node *) malloc(sizeof(node));  
                            List = insert_list(List, data, create_node(data));  
                            printf("Would you like to add another(y/n)?\n");  
                            scanf("%c", &x);  
                    }  
            }  
    }
    main_menu(List);  //the problem lies here
}  

this is the main menu

void main_menu(list* List)  
{  
    int x;  
    printf("Welcome to myCalendar version 1.0.0\n");  
    printf("Please input the number that you wish to do:\n");  
    printf("[1] Add Birthday Reminder\n");  
    printf("[2] Delete Birthday Reminder\n");  
    printf("[3] View Calendar\n");  
    printf("[4] Quit\n");  
    scanf("%d", &x);  
    getchar();  
    switch (x)  
    {  
            case 1:  
                    add_birthday(List);  
                    break;  
            case 2:  
                    delete_reminder(List);  
                    break;  
            case 3:  
                    view_calendar(List);  
                    break;  
            case 4:  
                    free(List);  
                    break;  
        }  
}

this is the main

int main(void)  
{  
    list* List = (list*) malloc(sizeof(list));  
    List = create_list(List);  
    main_menu(List);  
    return 0;  
}  

Is the definition of main_menu() is after add_birthday() ? If yes define main_menu() before add_birthday() . Also define all the methods before main() or atleast declare them before main() .

您没有将包含main.menu()声明的* .h包含在包含main()或add_birthday()的* .c中,也没有将错误指向任何地方。

Have you declared main_menu? In the absence of declaration a function is assumed to return 'int'. But, you function definition says, it is returning void. This is the cause of all the confusion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM