Jump to content

Recommended Posts

Posted

Inicialmente bom dia! Bem meu problema é o seguinte, tenho de criar uma lista encadeada com descritor. Já foram definidos nomes de funções e parâmetros. Na função init(), que inicia meu descritor, não consigo alocar memória para ele, como resposta, tenho que o tipo está incompleto.

lde.h

struct nodo{
int elemento;
struct nodo *ant, *prox;
};

struct desc_lista{
int tamanho;
struct nodo *inicio,*fim;
};

struct desc_lista * init();
//Aloca, inicializa e retorna um ponteiro para um descritor de lista;

lde.c

struct desc_lista *init(){
struct desc_lista *list;
list = malloc(sizeof(struct desc_lista));
if(list == NULL){
	printf("Erro ao alocar memória");
	exit(1);
}
list->inicio = NULL;
list->fim = NULL;
list->tamanho = 0;
return list;
}

Desde já agradeço pela ajuda!

Posted

Não estou a ver nenhum problema. O teu código executa sem problemas. Podes ser mais específico no erro que estás a obter?

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Posted

Faz o include do header no ficheiro de código

lde.c

#include "lde.h"
/* ... */

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.