Error >> TESTE500K.c:(.text+0x8f): Undefined Reference to `INSERT' <<

Asked

Viewed 555 times

0

Guys, I’m trying to create a list but it’s making these mistakes
TESTE500K.c:(.text+0x8f): Undefined Reference to `INSERT'

TESTE500K.c:(.text+0xa5): Undefined Reference to `IMPRIME'

[Error] Ld returned 1 Exit status

Would have to do with String (char*) that is another problem, but I decided to test first with char only that is not working.

    #include <stdlib.h>
    #include <stdio.h>

    struct agenda {
        int tel;
        char nome;
        struct agenda *prox;
    };
    typedef struct agenda Agenda;
    typedef Agenda *Ponteiro;

    void INSERE (Ponteiro *, int , char);
    void IMPRIME (Ponteiro);


    int main (){
        Ponteiro inicio = NULL;
        int telefone;
        char NOME;
        int escolha;
        printf ("DIGITE: \n 1 para Inserir \n 2 para Imprimir \n 3 para Finalizar \n");
        scanf ("%d", &escolha);
        if (escolha == 1){
            printf ("DIGITE O NOME: \n");
            scanf ("%c", &NOME);
            printf ("DIGITE O NUMERO: \n");
            scanf ("%d", &telefone);
            INSERE (&inicio, telefone, NOME);

        }
        else if (escolha == 2){
            IMPRIME (inicio);
        }
        else {
            return 0;
        }
        void INSERE (Ponteiro *sPtr, int novo_telefone, char novo_nome){
            Ponteiro novo, anterior, atual;
            novo = malloc (sizeof(Agenda));
            if (novo != NULL){
                novo->tel = novo_telefone;
                novo->nome = novo_nome;
                anterior = NULL;
                atual = *sPtr; 
                while (atual != NULL){
                    anterior = atual;
                    atual = atual ->prox;
                    if (anterior == NULL) {
                        novo->prox = *sPtr;
                        *sPtr = novo;
                    }
                    else{
                        anterior->prox = novo;
                        novo->prox = atual;
                    }
                }
            }
        }
        void IMPRIME(Ponteiro atual) {
            if (atual == NULL)
                printf( "A Agenda esta vazia.\n\n" ) ;

            else {
                printf( "A lista eh:\n");
                while (atual != NULL) {
                    printf("%c", atual->nome);
                    printf("%d", atual->tel);

                    atual = atual -> prox;
                }
            }
    }
    }
  • Hi Jorge! Welcome to Stack Overflow! I wish you could edit your question a little better, it’s a little hard to understand, see this link to get an idea of how to edit it.

1 answer

0


After

 else {
        return 0;
    }

there should be one more key, which would close the function main(). Without the key, you’re basically setting the functions IMPRIME() and INSERE() inside main(), which is impossible in C, so the functions are not being created, and your compiler doesn’t know what to do.

You also need to remove the last key from the program, as that is where your program is currently ending.

  • 1

    In fact GCC allows the creation of functions within other functions such as language extension, but these internal functions do not have access to the surrounding lexical scope such as functions in javascript or lua, for example. Wikipedia in English has a great article about the problem.

  • @Wtrmute Thank you for your comments.

Browser other questions tagged

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