in Education by
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)

1 Answer

0 votes
by
Your code generates the following error: In member function ‘void LinkedList::insertAtEnd(char*, char*, char*, int)’: error: incompatible types in assignment of ‘char*’ to ‘char [20]’. You must copy each value from your function parameter to your node(I mean do temp->nome[0] = n[0] for each value in your array). You can change your node structure to use pointers instead of arrays and this would become easier. If you want to find out more, check the following link : https://www.tutorialspoint.com/cplusplus/cpp_passing_arrays_to_functions.htm

Related questions

0 votes
    Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    Tm trying to get the difference of 2 sets in linked list Example: Input: Set A: 1 - 2 - 3 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to understand the usage of private const in the class. My understanding is that private const is used to make ... (void) { int const MyExample::x = 3; std::cout...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    As far as I know, in gcc you can write something like: #define DBGPRINT(fmt...) printf(fmt); Is ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 18, 2022 in Education by JackTerrance
0 votes
    I am following simple examples to build up my understanding on private static members. However, I am getting ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I wrote a program which gets matches between 2 pictures. And this is the code. but if I use ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a managed C++ dll which uses a unmanaged C++ lib. I've added the lib file in the ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    ___________ function gives an error message if the desired package cannot be loaded. (a) Dplyr (b) Require (c ... of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    _______ allows you to modify the error behavior so that you can browse the function call stack (a) debug() ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I wrote a program which gets matches between 2 pictures. And this is the code. but if I use ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    __________ prints out the function call stack after an error occurs. (a) trace() (b) traceback() (c) ... Debugging of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
...