Fixing Code to Print "Print": Nodes and Pointers Programming Error

  • Context:
  • Thread starter Thread starter needOfHelpCMath
  • Start date Start date
  • Tags Tags
    Nodes Pointers
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
needOfHelpCMath
Messages
70
Reaction score
0
what is wrong with my programming D: won't print out the "Print"
Code:
 #include <iostream>
#include <cstdlib>
#include<string>

using namespace std;

class Node {   
public:
   Node();
   Node* prev;
   string key;
   Node* next;
   
};

Node::Node() {
   prev = 0;
   next = 0;
   
   return;
}
   

class LinkedList {
public:
  LinkedList();
  void Insert(string key);
  void Print();
  Node* Find(string key);
  void Delete(Node* x);

  Node* head;
};

LinkedList::LinkedList() {
   head = 0;

   
   return;
}
 
 void LinkedList::Insert(string key) {
    Node* n;
    n = new Node;
      n->key = key;
     
      
      // Link new node to current head
      // of list
      n->next = head;
     
      // Make head point to new node
      head = n;
      return;
   }
   
   void LinkedList::Print() {
      Print* c;
      
      return;
   }int main () { 
  LinkedList l;
  Node* n = 0;
  string line;
   
  
    while (true){

     getline(cin, line);
     if (line.empty()){
        break;
     }

     l.Insert(line);
  }

   n = l.head(c);
   
   while (n!=0){
      cout << n->key << endl;
      n = n->next;
   }
   return 0;
}

I want to print out "Print" with the arrow

Code Runs:

Code:
main.cpp: In member function 'void LinkedList::Print()':
main.cpp:58:14: error: 'c' was not declared in this scope
       Print* c;
              ^
main.cpp: In function 'int main()':
main.cpp:80:15: error: 'c' was not declared in this scope
    n = l.head(c);
               ^
main.cpp:80:16: error: expression cannot be used as a function
    n = l.head(c);
^
 
Physics news on Phys.org
HallsofIvy said:
The first error message essentially tells you the problem: In "LinkedList.Print()" you have "Print* c" but I see no other mention of "c". Where is "c" defined?

ahhhh okay i see thank you!