"Local variable not initialized p used

Asked

Viewed 380 times

-1

I’m developing a c++ program to learn malloc, but is giving local variable error in main function:

// testeMalloc.cpp : define o ponto de entrada para o aplicativo do console.
//

#include "stdafx.h"
#include <stdlib.h>

#define MAX 100;
#define true 0;
#define false 1;

struct fila {
    int *f;
    int ini, fim;
    float vet[100];
};

typedef fila Fila;


int incr(int i) {


    return (i + 1) % MAX;
}

Fila *cria() {

    Fila *f = (Fila*) malloc(sizeof(Fila));

    f->ini = 0;
    f->fim = 0;

    return f;
}

int inserir(Fila *f, float vet) {

    int cFim = incr(f->fim);

    if (cFim == f->ini) {

        printf("\nFila Cheia");

        return false;
    }

    else {
        int final;

        final = f->fim;

        f->vet[final] = vet;
        f->fim = incr(f->fim);

        printf("\nInserido com Sucesso!");

        return true;
    }

}


float retira(Fila *f) {

    if (f->ini == f->fim) {

        printf("\nFila vazia, valor não retirado");

        return 1;
    }

    float retorno = f->vet[f->ini];

    f->ini = incr(f->ini);

    return retorno;
}

int vazia(Fila *f) {
    if (f->ini == f->fim) {
        return true;
    }
    else
        return false;
}

void libera(Fila *f) {

    free(f);
}

void imprime(Fila *f) {


    for (int i = f->ini; i < f->fim; i = incr(i)) {
        printf("\nValor na posição %d: %.2f\n", i, f->vet[i]);
    }
}


int main()
{
    Fila *p;
    int soma1 = 0;

    *cria();

    inserir(p, 10);

    inserir(p, 200);

    float tmp = retira(p);

    libera(p);

    printf("\nNa soma dos valores: %d", soma1);

    return 0;
}

Any tips on how to make this program compile?

1 answer

-1

Solved the problem, assigns the value of the pointer function creates to the variable p.

Browser other questions tagged

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