Warning: implicit declaration of function 'showMenu' [-Wimplicit-function-declaration]

432 views Asked by At

I get this weird warning message in Visual Studio Code the whole time and have no idea what else I should change.

Message:

warning: implicit declaration of function 'showMenu' [-Wimplicit-function-declaration]

This is the code:

#include <stdio.h>

int main() {
   
   showMenu();

    return 0;
}

int showMenu() {
   
    printf(" Herzlich willkommen \n");
    printf("(0) Telefonnummern anzeigen\n");
    printf("(1) Neue Nummer hinzufügen\n");
    printf("\n\n");
  
    return 0;
}

Hope someone can help me.

greetings

" ; if ($?) { gcc Adressbuch.c -o Adressbuch } ; if ($?) { .\Adressbuch }
Adressbuch.c: In function 'main':
Adressbuch.c:5:4: warning: implicit declaration of function 'showMenu' [-Wimplicit-function-declaration]
    showMenu();
    ^~~~~~~~
 Herzlich willkommen 
(0) Telefonnummern anzeigen
(1) Neue Nummer hinzuf├╝gen

I get the results, but with the error message in it.

2

There are 2 answers

0
Vlad from Moscow On

The function shall be declared before its usage as for example before main

int showMenu( void );

int main( void )
{
    //...
}

Pay attention to that the return type int of the function does not make a great sense. You could declare it like

void showMenu( void );
1
jvieira88 On

Just add a prototype to your showMenu function before the main. Example

int showMenu (); //Function prototype here

int main() {
   
   showMenu();

    return 0;
}

int showMenu() {
   
    printf(" Herzlich willkommen \n");
    printf("(0) Telefonnummern anzeigen\n");
    printf("(1) Neue Nummer hinzufügen\n");
    printf("\n\n");
  
    return 0;
}