Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Program error please help (pointers and lists)

This topic is 5662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!