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

In summary, the conversation discusses a program that is not printing out a specific word, "Print", and the code provided includes a class and functions for a linked list data structure. The errors in the code are due to a variable, "c", not being declared or defined in relevant places.
  • #1
needOfHelpCMath
72
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);
^
 
Technology news on Phys.org
  • #2
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?
 
  • #3
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!
 

1. Why am I getting a "Print" error in my code?

There could be several reasons for this error. It could be due to a syntax error, missing libraries or dependencies, incorrect variable names, or an issue with the logic of your code. It is important to carefully review your code and check for any mistakes.

2. How can I fix the "Print" error in my code?

To fix this error, you can start by checking for any syntax errors and making sure all necessary libraries are included. Then, review your code and double check all variable names and logic. You may also want to try debugging your code to identify any specific errors or issues.

3. Can "Print" errors be caused by issues with nodes and pointers?

Yes, "Print" errors can sometimes be caused by problems with nodes and pointers. This could be due to incorrect syntax or logic in your code, or issues with the data structure you are using. It is important to carefully review your code and make sure all nodes and pointers are correctly implemented.

4. How can I prevent "Print" errors from occurring in the future?

To prevent "Print" errors, it is important to carefully review your code before running it and check for any mistakes. You can also use debugging tools to identify and fix errors before they cause issues. Additionally, it is helpful to have a good understanding of the programming language and data structures you are using.

5. Are there any common mistakes that can lead to "Print" errors?

Yes, some common mistakes that can lead to "Print" errors include using incorrect syntax, not properly initializing nodes and pointers, and incorrect logic in your code. It is important to carefully review your code and check for these types of mistakes to prevent "Print" errors.

Similar threads

  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
820
  • Programming and Computer Science
Replies
5
Views
885
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
3
Views
896
Back
Top