GCC C compile error, void value not ignored as it ought to be

前端 未结 5 1358
长情又很酷
长情又很酷 2020-12-20 15:40

I\'m having trouble compiling some C code. When I compile, I\'l get this error:

player.c: In function ‘login’:  
player.c:54:17: error: void value not igno         


        
5条回答
  •  鱼传尺愫
    2020-12-20 16:13

    You must declare void functions before use them. Try to put them before the main function or before their calls. There's one more action you can do: You can tell the compiler that you will use void functions.

    For exemplo, there are two ways to make the same thing:

    #include 
    
    void showMsg(msg){
        printf("%s", msg);
    }
    
    int main(){
        showMsg("Learn c is easy!!!");
        return 0;
    }
    

    ...and the other way:

    #include 
    
    void showMsg(msg); //Here, you told the compiller that you will use the void function showMsg.
    
    int main(){
        showMsg("Learn c is easy!!!");
        return 0;
    }
    
    void showMsg(msg){
        printf("%s", msg);
    }
    

提交回复
热议问题