a Function-Definition is not allowed here before '{' what does this error mean?

Asked

Viewed 5,430 times

0

I am trying to compile my code, but the compilation returns the following error:

a Function-Definition is not allowed here before '{' token|

I am beginner and I have looked several times the code to understand what may be happening, but I did not find the origin of the error.

void menuAlunoCurso(){

        opcao = 0;
        system("cls");
        printf("\t\t\tSisCA - Menu do Matriculado *****");
        printf("\n\n\t\t\t *** Escolha uma opção ***");
        printf("\n\t\t\t 1------Cadastrar");
        printf("\n\t\t\t 2------Exibir");
        printf("\n\t\t\t 3------Pesquisar");
        printf("\n\t\t\t 4------Remover");
        printf("\n\t\t\t 7------Voltar ao menu anterior");
        printf("\n\n\t\t\tOpção: ");
        scanf("%d",&opcao);

    }

Could someone help me, please? Until yesterday the code ran perfectly.

  • Do you only have that part of the code? Because I circled it here and it worked. Actually I just made a modification in which I put the type of the option variable. Getting int opcao = 0;

  • Probably your function is inserted in an inappropriate location. Please edit the question to show all possible code. @Leonardocoelho I think this variable is defined outside the function.

  • @felipeptcho may be that yes, because as I said, here it worked the way I tried.

2 answers

2

Usually this error occurs when you forgot to close some key in the previous function

Example:

void outraFuncao(){
    //
    // Codigo da função...
    //
// Falta o } para essa função

void menuAlunoCurso(){

    opcao = 0;
    system("cls");
    printf("\t\t\tSisCA - Menu do Matriculado *****");
    printf("\n\n\t\t\t *** Escolha uma opção ***");
    printf("\n\t\t\t 1------Cadastrar");
    printf("\n\t\t\t 2------Exibir");
    printf("\n\t\t\t 3------Pesquisar");
    printf("\n\t\t\t 4------Remover");
    printf("\n\t\t\t 7------Voltar ao menu anterior");
    printf("\n\n\t\t\tOpção: ");
    scanf("%d",&opcao);

}

1

You set the function definition "menuAlunoCurso" before the final key "}" of the previous function.

Something like that:

void func()
{
    // bla
    // bla
    // bla

void menuAlunoCurso(){
   // bla
   // bla
   // bla
} // chave final de menuAlunoCurso 

} // chave final de func

Browser other questions tagged

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