#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int id;
int salary;
struct node *next;
char name[30];
} List;
int main() {
List *head = (List *) malloc(sizeof(List)); //allocated memory for head
if(head == NULL) {
return 1;
}
head -> id = 332513075;
head -> salary = 100;
head -> name = "Name Lastname";
// head -> phone = "0532554891";
// head -> position = "CEO";
head -> next = NULL;
print_list(*head);
return 0;
}
Error message: array type 'char [30]' is not assignable
What is going wrong here and how to fix it?
Arrays are non-modifiable lvalues. That is arrays do not have the assignment operator. You have to copy elements from one array into another.
So instead of this statement
head -> name = "Name Lastname";
write
#include <string.h>
//...
strcpy( head -> name, "Name Lastname" );