Closed. This question needs debugging details. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 3 years ago.
Improve this question
I've created a singly linked list, and it was running perfectly, that is until I changed my "basic" data structure from a single int value to a variety of variables.
The error occurs in the insertAtEnd function, when I try to store the data it gets from the parameters on the temp node.
temp->nome = n;
temp->morada = m;
temp->telefone = t;
temp->idade = i;
The int value shows no error, but the char[] ones get the error "E0137 - expression must be a modifiable lvalue".
List.h
struct node
{
char nome[20];
char morada[30];
char telefone[9];
Int idade;
node *next;
};
class LinkedList
{
private:
node *head;
node *tail;
public:
LinkedList();
~LinkedList();
void insertAtEnd(char n[20], char m[30], char t[9], int i);
void insertAtStart(char n[20], char m[30], char t[9], int i);
void display(void);
void deleteFirst(void);
void deleteLast(void);
void deleteAtPosition(int pos);
};
List.cpp
(...)
LinkedList::LinkedList()
{
head = NULL;
tail = NULL;
}
void LinkedList::insertAtEnd(char n[20], char m[30], char t[9], int i)
{
node *temp = new node;
temp->nome = n;
temp->morada = m;
temp->telefone = t;
temp->idade = i;
temp->next = NULL;
if (head == NULL)
{
head = temp;
tail = temp;
temp = NULL;
}
else
{
tail->next = temp;
tail = temp;
}
}
(...)
Main.cpp
(...)
LinkedList lista;
char nome[20];
char morada[30];
char telefone[9];
int idade;
(...)
switch (op) {
case 1:
cout << "Inserir nome: ";
cin >> nome;
cout << "Inserir morada: ";
cin >> morada;
cout << "Inserir telefone: ";
cin >> telefone;
cout << "Inserir idade: ";
cin >> idade;
lista.insertAtEnd(nome, morada, telefone, idade);
break;
(...)
Those are some blocks of code from my project I think are relevant, I'm almost sure there's nothing else on it that would matter to this issue, but if you do think so, comment and I'll edit it.
Thanks in advance.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)