Having a problem with assigning a string in this linked list, any ideas?
the line that reports an error is highlighted in red.

I would expect this to work as variable 'name' is a char array and i am simply assigning the string "Vin" to it.

#include<stdlib.h>
#include<stdio.h>

typedef struct // TV Guide entry struct declaration
{
        char name[50];
        char day[10];
        int time;
}Entry;

typedef struct LinkedListNode // LinkedListNode declaration
{
       Entry* entry; // Points to Entry struct
       struct LinkedListNode* next; // Points to the next node
}LinkedListNode;

typedef struct // LinkedList declaration
{
        int listLength;
        LinkedListNode* head; // Points to first node of linkedlist
}LinkedList;

void createList() // Creates an empty linkedlist
{
     LinkedList* entryList;
     entryList = (LinkedList*)malloc(sizeof(LinkedList));
     entryList -> head = NULL;
     entryList -> listLength = 0;   
}

void insertFirst( LinkedList* entryList )
{
     	LinkedListNode* newNode;
	newNode = (LinkedListNode*)malloc(sizeof(LinkedListNode));
	newNode -> entry -> name = "Vin"; // <- NOT WORKING!
	newNode -> next = entryList -> head;
}

You're writing C which simulates a string with a character array. You can't use = to assign arrays. Look up string.h functions...

Thanks, ended up changing the line to:

strcpy( newNode->entry->name , "Vin" );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.