Error in my C program

Asked

Viewed 149 times

1

I need to create a program in C, which removes (or copies) the values of a queue, using the output rules of a stack and add them into a new structure.

I rode as below but there are two errors:

"Undefined Reference to 'Winmain@16' File not found: ctr0_c. c"

"error:id returned 1 Exit status File not found: collect2.exe"

Can anyone help me where I’m going wrong? What should I change?

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

//Constantes
#define tamanho 5

//Fila
struct estrutura{
   int dados [tamanho];
   int ini;
   int fim;
};

//variaveis globais
struct estrutura fila;
struct estrutura pilha;
int op;

//prototipacao
void fila_entrar();
void fila_sair();
void fila_mostrar();
void menu_mostrar ();
void pilha_mostrar();
void pilha_mover();

//funcao principal
int mais(){
    setlocale(LC_ALL, "Portuguese");
    op=1;
    fila.ini=0;
    fila.fim=0;
    pilha.ini=0;
    pilha.fim=0;
    while(op!=0){
        system("cls");
        fila_mostrar();
        pilha_mostrar();
        menu_mostrar();
        scanf("%d", &op);
        switch(op){
        case 1:
            fila_entrar();
            break;
        case 2:
            fila_sair();
            break;
        case 3:
            pilha_mover();
            break;
        }
    }
    return(0);
}

//add elemento no final da fila
void fila_entrar(){
    if(fila.fim==tamanho){
        printf("\nA fila está cheia\n");
        system("Pause");
    }else{
        printf("\nDigite o valor a ser inserido: ");
        scanf("%d", &fila.dados[fila.fim]);
        fila.fim++;
    }
}

//retirar o primeiro elemento da fila
void fila_sair(){
    if(fila.ini==fila.fim){
        printf("\nA fila esta vazia, adicione algum valor\n");
        system("Pause");
    }else{
        int i;
        for(i=0;i<tamanho;i++){
            fila.dados[i]=fila.dados[i+1];
        }
        fila.dados[fila.fim]=0;
        fila.fim--;
    }
}

//mostra o conteudo da fila
void fila_mostrar(){
    int i;
    printf("[ ");
    for(i=0;i<tamanho;i++){
        printf(" %d", fila.dados[i]);
    }
    printf(" ]\n\n");
}

//mostra o menu de opções
void menu_mostrar(){
    printf("\nEscolha uma opção:\n");
    printf("1- Incluir na fila\n");
    printf("2- Excluir da fila\n");
    printf("3- Mover para a pilha\n");
    printf("0-Sair\n\n");
}

//mostrar conteudo da pilha
void pilha_mostrar(){
    int i;
    printf("[ ");
    for(i=0;i<tamanho;i++){
        printf(" %d", pilha.dados[i]);
    }
    printf(" ]\n\n");
}

//mover para a pilha
void pilha_mover(){
    if(fila.ini==fila.fim){
        printf("\nA fila esta vazia, adicione algum valor\n");
        system("Pause");
    }else{
        pilha.dados[pilha.fim]=fila.dados[fila.fim];
        pilha.fim++;
    }
}

1 answer

2


"Undefined Reference to 'Winmain@16' File not found: ctr0_c. c"

I mean, you didn’t set the function main nowhere. What happens is that you typed it wrong, placed it mais() instead of main(). Also, or you will have to put your function main at the end or else declare a prototype of it at the beginning the same way you did for the other functions.

  • Thank you very much !!! I reviewed and passed beaten... Can you give me another hand ? Why the Move to Stack function does not work ?

  • @Tejota In function pilha_mover, it seems to me that you take an element of the queue without removing it from there. Also, in the functions pilha_mover and fila_sair, you seem to take the elements from the back of the queue, and not at the beginning.

  • @Victorstafusa: the function main() does not need prototype. Put the function main() in the end has only the functionality to consider the definition of other functions as prototype.

Browser other questions tagged

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