ERROR: Static declaration of Follows non-static declaration

Asked

Viewed 836 times

0

My code has the following error and I’m not seeing or understanding what it is.

80:6: error: Static declaration of 'print_menu' Follows non-static declaration void print_menu(){

14:6: note: Previous declaration of 'print_menu' was here void print_menu();

Code:

/* <-- BIBLIOTECAS --> */
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include "game_pvp.h"
/* <-- BIBLIOTECAS --> */

/* <-- DEFINES --> */
#define TAM 3
/* <-- DEFINES --> */

/* <-- DECLARAÇÃO DE PROCEDIMENTOS --> */
void print_menu();
void print_new_game();
void print_game_level();
void print_pvp_menu();
/* <-- DECLARAÇÃO DE PROCEDIMENTOS --> */

/* <-- MAIN --> */
int main(){
    char menu_choice;
    char game_shape[TAM][TAM];
    int start_player;

    srand(time(NULL));

    print_menu();
    menu_choice = getch();
    while(menu_choice < 49 || menu_choice > 51) {
        printf("\n Please enter a valid option");
        menu_choice = getch();
    }
    if(menu_choice == 49){
        system("cls");
        print_new_game();
        menu_choice = getch();
        while(menu_choice < 49 || menu_choice > 50) {
            printf("\n Please enter a valid option");
            menu_choice = getch();
        }
        if(menu_choice == 49){
            system("cls");
            print_game_level();
            menu_choice = getch();
            while(menu_choice < 49 || menu_choice > 51) {
                printf("\n Please enter a valid option ");
                menu_choice = getch();
            }
            system("cls");
            // CHAMA JOGADOR vs IA Passando o nivel
        }
        else{
            system("cls");
            print_pvp_menu();
            start_player = (rand() % 2) + 1;
            if(start_player == 1){
                printf("\n  O Player 1 comeca (press any key)");
            }
            else{
                printf("\n  O Player 2 comeca (press any key)");
            }
            getch();
            system("cls");
            // CHAMA JOGADOR vs JOGADOR Passando a vez

            game_pvp(game_shape, start_player);
        }

    }
    // Aqui entra game save e EXIT


    system("pause");
}

/* <-- MAIN --> */

/* <-- PROCEDIMENTOS --> */
void print_menu(){
    printf("\n -=- JOGO DA VELHA -=- \n");
    printf("\n 1 - New Game");
    printf("\n 2 - Saved game");
    printf("\n 3 - EXIT");
    printf("\n Enter your choice ");
}

void print_new_game(){
    printf("\n -=- JOGO DA VELHA -=- \n");
    printf("\n 1 - One player");
    printf("\n 2 - Two players");
    printf("\n Enter your choice ");
}

void print_game_level(){
    printf("\n -=- GAME LEVEL -=- \n");
    printf("\n 1 - Easy");
    printf("\n 2 - Medium");
    printf("\n 3 - Hard");
    printf("\n Enter your choice ");
}

void print_pvp_menu(){
    printf("\n -=- PLAYER vs PLAYER -=- \n");
    printf("\n X - Player 1");
    printf("\n O - Player 2");
    printf("\n\n Sorteando quem vai comecar ...");
}
/* <-- PROCEDIMENTOS --> */

compiling_error:

C:\Users\Gabriel\Desktop\jogo da velha\main.c:80:6: error: static declaration of 'print_menu' follows non-static declaration
 void print_menu(){
      ^~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:14:6: note: previous declaration of 'print_menu' was here
 void print_menu();
      ^~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:88:6: error: static declaration of 'print_new_game' follows non-static declaration
 void print_new_game(){
      ^~~~~~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:15:6: note: previous declaration of 'print_new_game' was here
 void print_new_game();
      ^~~~~~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:95:6: error: static declaration of 'print_game_level' follows non-static declaration
 void print_game_level(){
      ^~~~~~~~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:16:6: note: previous declaration of 'print_game_level' was here
 void print_game_level();
      ^~~~~~~~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:103:6: error: static declaration of 'print_pvp_menu' follows non-static declaration
 void print_pvp_menu(){
      ^~~~~~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:17:6: note: previous declaration of 'print_pvp_menu' was here
 void print_pvp_menu();
      ^~~~~~~~~~~~~~
C:\Users\Gabriel\Desktop\jogo da velha\main.c:108:1: error: expected declaration or statement at end of input
 }
 ^

game_pvp. h:

#include "game_pvp.c"

game_pvp. c:

int game_pvp(char game_shape[3][3], int turn){
    char x, y;

    if(turn == 1){
        print_shape(turn);
        printf("\n Enter a value for X: ");
        x = getch();
        printf("%c",x);
        while(x < 49 || x > 51 ){
            printf("\n Please enter a valid option");
            x = getch();
        }
        printf("\n Enter a value for Y: ");
        y = getch();
        printf("%c",y);
        while(y < 49 || y > 51 ){
            printf("\n Please enter a valid option");
            y = getch();
        }
    }
    else{
        print_shape(turn);
        printf("\n Enter a value for X: ");
        x = getch();
        printf("%c",x);
        while(x < 49 || x > 51 ){
            printf("\n Please enter a valid option");
            x = getch();
        }
        printf("\n Enter a value for Y: ");
        y = getch();
        printf("%c",y);
        while(y < 49 || y > 51 ){
            printf("\n Please enter a valid option");
            y = getch();
    }

}

void print_shape(int turn){

        printf("\n -=- PLAYER %i TURN -=- \n", turn);
        printf("\n");
        printf("      1   2   3   Y\n");
        printf("\n");
        printf(" 1    X | X | X \n");
        printf("     ---|---|--- \n ");
        printf("2    X | X | X \n");
        printf("     ---|---|--- \n ");
        printf("3    X | X | X \n");
        printf("\n X\n");

}
  • Try switching to Static void print_game()... in your function

  • Must have a print_menu() elsewhere. Alias one of the reasons I hate separate statement of the definition.

  • I put Static in front and it didn’t help.

  • Tbm changed print_menu() to print_menu2() and continued with the bug but now in print_menu2()

  • What is the content of .h?

  • And which compiler? If possible, which build flags?

  • Oops, Jefferson. I commented on the part . h is back to work, I’ll put the contents of it.

  • @Gabrieldantas the problem is in .h, that you include the .c

  • What’s wrong with . h Jefferson ?

  • @Gabrieldantas the .h should not have code, only declaration. So do not include files .c, the behavior that the compiler will perform will not be what you expect, the cycle of compiling a source C separately is distinct from what you imagine; more details in this answer: https://answall.com/a/213804/64969

  • In response, I put the behavior of #include"hello.c" in a project and showed what inconsistency generated

Show 6 more comments

1 answer

2


Your problem is that there is a gap of {} in the archive game_pvp.c. You forgot to close one } in function int game_pvp(char game_shape[][3], int turn)

Now the big problem even is that you are using the file . h in the wrong way. It does not have the purpose of including a file . c, as you did, but of being a header where vc puts the statements of the functions and structures that your program will use.

Therefore, the correct way to create the game_pvp.h, would be something like:

#ifndef __GAME_PVP_H__
#define __GAME_PVP_H__

int game_pvp(char game_shape[][3], int turn);
void print_shape(int turn);

#endif /* __GAME_PVP_H__ */
  • It makes total sense. I thought it was an AP typo

  • Thanks friend, I will give a study on this . h

Browser other questions tagged

You are not signed in. Login or sign up in order to post.