I'm doing my coursework regarding airport simulation and I'm having some troubles trying to store information in the character array part.
I am supposed to type in a string of character and it will store in the planeName
part of the node but it can't seem to work. My int main()
is pretty much empty now because I didn't want to continue coding with incorrect 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 the error message in the line containing: temp -> planeName = name
This is the part where error message pops up and I have no clue why is this happening.
Can someone please help and ask more questions me if my question is not clear enough?
temp -> planeName = name;
You can't assign to an array. Array cannot be used as lvalue. Use strcpy
instead-
strcpy(temp -> planeName,name);
Note- But make sure your char
arrays are nul terminated before passing them to strcpy
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With