skip to Main Content

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 anzeigenn");
    printf("(1) Neue Nummer hinzufügenn");
    printf("nn");
  
    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

Answers


  1. 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 );
    
    Login or Signup to reply.
  2. 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 anzeigenn");
        printf("(1) Neue Nummer hinzufügenn");
        printf("nn");
      
        return 0;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search