This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

linked lists in lpc2136 error initializing pointers in null

Hello to everyone

I am creating a linked list that contains id and name information. I am having a runtime error when I initialize list_node * newlist = {NULL} already contains it has information just like list_node newnode and it doesn't allow me to initialize in null.

. What should I do to initialize everything in NULL without new data.

typedef struct nodo list_node;

struct nodo
{
	int count;
	char name[20];
	struct nodo *p1;
};

struct nodo *crearlista_ssid(char *[5]);

struct nodo * crearlista_ssid(char *array[5])
{
	
	char *lista2;
	list_node *newlist={NULL},*aux={NULL};
	
	for(int i=0;i<=4;i++)
	{
			list_node *newnode= (list_node*) malloc(sizeof(list_node));
			if(newnode)
			{
				newnode->count=i+1;
				lista2= strtok(array[i], ",");
				lista2= strtok(NULL, ",");
				strcpy(newnode->name,lista2);
				
				newnode->p1=NULL;
				if(newlist->p1==NULL)
					newlist=newnode;
				else
				{
					aux=newlist;
					while(aux->p1!=NULL)
					{
						aux=aux->p1;
					}
					aux->p1=newnode;
				}
				
				
			}
	}
	return newlist;
}