-1
I’m trying to implement a dynamic Fila. When I start the program (start and end = NULL), and then place to queue a value (queue function) the pointer "end" receives the new queue item, but the "start" does not, and in the function I am asking for the "start" and the "end" to receive the new queue item.
Follow the code for testing:
#include <stdio.h> 
#include <stdlib.h>
#include <stdbool.h>
struct no {
    int dado;
    struct no *prox;
};
void enfileirar(struct no **inicio, struct no *fim, int valor) {
    struct no *novoNo;
    novoNo = (struct no *) malloc(sizeof(struct no));
    novoNo->dado = valor;
    novoNo->prox = NULL;
    if (*inicio == NULL) {
        *inicio = novoNo;
    } else {
        *fim->prox = *novoNo;
    }
    *fim = *novoNo; 
}
void mostrarFila(struct no **inicio) {
    struct no *aux;
    aux = inicio;
    printf("Inicio da fila -> \n");
    while(aux == NULL) {
        printf("%d\n", &aux->dado);
        printf("\n");
        aux = aux->prox;
    }
    printf("<- Fim da fila \n");
}
int main(int argc, char** argv) {
    struct no *inicio, *fim;
    int resposta, valor;
    bool sair = true;
    while(sair) {
        printf("\n");
        printf("************** MENU **************\n");
        printf("0 - Sair do programa\n");
        printf("1 - Iniciar Fila\n");
        printf("2 - Enfileirar\n");
        printf("3 - Mostrar fila\n");
        printf("**********************************\n");
        scanf("%d", &resposta);
        switch(resposta) {
            case 0:
                sair = false;
                printf("Saindo do programa...\n");
                break;
            case 1:
                inicio = NULL;
                fim = NULL;
                break;
            case 2:
                printf("digite o valor para inserir na fila:\n");
                scanf("%d", &valor);
                enfileirar(&inicio, &fim, valor);
                printf("%d\n", &inicio->dado);
                printf("%d\n", &fim->dado);
                break;
            case 3:
                mostrarFila(&inicio);
                break;
            default:
                sair = false;
                printf("Saindo do programa...\n");
                break;
        }
    }
    return 0;
}
Thanks solved my problem =) I lack study yet...
– Eduardo Albuquerque