I cannot save character string in node of linked list

I am doing my term paper on airport simulations, and I am having problems trying to save information in part of an array of characters.

I have to enter a character string and it will be stored in planeNamethe node part, but it cannot work. Mine is int main()now pretty empty because I didn’t want to continue coding with the wrong functions.

Below are my codes:

struct node {
    char planeName[5];
    int planeNumber;
    struct node* next;
}; 

struct node* front = NULL;
struct node* rear = NULL;

void Enqueue(char name[5], int x);

int main() {

}

void Enqueue(char name[5], int x){

    struct node* temp = (struct node*)malloc(sizeof(struct node));

    temp -> planeName = name; 
    temp -> planeNumber = x;
    temp -> next = NULL;

    if (front == NULL && rear == NULL)
        front = rear = temp;
    rear -> next = temp; //set address of rear to address of temp
    rear = temp; //set rear to point to temp

    return;
}

This is an error message on a line containing:temp -> planeName = name

This is the part where the error message appears, and I do not know why this is happening.

Can someone please help and ask me more questions if my question is not clear enough?

+4
source share
3

- , , planeName.

, , , , , \0.

, , \0: null . , . , :

char * strcpy ( char * destination, const char * source );

, source destination. :

strcpy(temp -> planeName,name);

strcpy().

+1
temp -> planeName = name;

. lvalue. strcpy -

strcpy(temp -> planeName,name);

. , char strcpy.

+5

Your lines are arrays of characters, so you need to copy individual elements. Fortunately, there are functions (e.g. strcpy) written for this.

+2
source

Source: https://habr.com/ru/post/1622448/


All Articles