Skip to main content
GameDev.net gamedev.net
🔒 Locked

Program error please help (pointers and lists)

Started by TheShadow Mar 23, 2003 at 5:34 PM 1 replies 200+ views
Original Post
TheShadow
TheShadow
I got the following code to add items to a list (its still a learning phase)
  
#include <iostream>
using std::cout;
using std::endl;


struct lista {
	struct lista *nodo;
	char dato;
};

typedef struct lista NODO;
typedef NODO *a_NODO;

void agregar(a_NODO *, char);

void main()
{
	a_NODO comienzo = NULL;
	agregar(&comienzo, ''A'');

}

void agregar(a_NODO *apuntador, char valor)
{
	a_NODO apuntador_nuevo, apuntador_ant, apuntador_act;
	apuntador_nuevo = malloc(sizeof(NODO)); //This is line 26

	if(apuntador_nuevo != NULL) {
		apuntador_nuevo->dato = valor;
		apuntador_nuevo->nodo = NULL;

		apuntador_ant = NULL;
		apuntador_act = *apuntador;
	}
}
  
And i get the following error C:\Program Files\Microsoft Visual Studio\MyProjects\addnode\main.cpp(26) : error C2440: ''='' : cannot convert from ''void *'' to ''struct lista *'' Conversion from ''void*'' to pointer to non-''void'' requires an explicit cast Error executing cl.exe. addnode.exe - 1 error(s), 0 warning(s)
Mecha Engineer (Making Real Humanoid Suits)
falkone
falkone
Your Malloc function.. when you allocate memory, it returns a POINTER to that memory.. in your code you are trying to store the return in a structure
Disclaimer: "I am in no way qualified to present advice n any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)" o
TheShadow
TheShadow
What should i do? this is how my book handles it... h.m/p.j deitel book of how to program in c++
Mecha Engineer (Making Real Humanoid Suits)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.