2

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;
}

7
  • Why do you have a separate List and newEmployeeList which are exactly equivalent aside from the name? Commented May 18, 2021 at 16:05
  • 1
    List and newEmployeeList are two different types. You should only have one type for both. Just get rid of the newEmployeeList type and use List in its place. Commented May 18, 2021 at 16:05
  • I have to create a new struct, because that's a requirement from the professor. I can't change it. @AKX Commented May 18, 2021 at 16:06
  • 1
    @zaro A new type of struct, or a new instance of an existing struct? Commented May 18, 2021 at 16:08
  • @dbush new list, which will contain only certain employees Commented May 18, 2021 at 16:11

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. The reasno to have newEmployeeList is becuase it is a requirement from the professor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.