Reputation: 83
I am writing a program with in which I have to create a list of employees and work with the information in it. In the writeToFile
I write the info. to a .txt
file. In the newList
I should create a new list, which will contain employees which match certain criteria. However, when I intiliaze *newListHead
pointer I get initialization of 'newEmployeeList *' {aka 'struct newEmployeeList *'} from incompatible pointer type 'List *' {aka 'struct List *'} [-Wincompatible-pointer-types]|
error. What am I doing wrong since I did the same thing for the head
pointer?
typedef struct employee {
char name[20];
double salary;
char gender[10];
} employee;
typedef struct List {
employee info;
struct List *next;
} List;
typedef struct newEmployeeList {
employee info;
struct newEmployeeList *next;
} newEmployeeList;
List *create_new_node() {
List *new_node = NULL;
new_node = (List*)malloc(sizeof(List));
new_node->next = NULL;
return new_node;
};
int main()
{
List *head = create_new_node();
writeToFile("test.txt", head);
newEmployeeList *newListHead = create_new_node();
newList(head, newListHead);
return 0;
}
Upvotes: 2
Views: 356
Reputation: 225757
As the error message says, the create_new_node
function is returning a List *
but you're assigning that value to a newEmployeeList *
. Those types are incompatible.
Either change the type of newListHead
to List *
or create a different function that returns a new instance of newEmployeeList *
. I'd recommend the former as there's no reason to even have the type newEmployeeList
from what you've shown.
Upvotes: 1