| | |
linked list
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2007
Posts: 67
Reputation:
Solved Threads: 0
Hi
I try to fill linked list with names. I have one error could anyone fix it.
the error I have is:
44 C:\Documents and Settings\mauro\Desktop\c++\nodes- read names switched them around and display them.cpp expected primary-expression before ']' token
thx
I try to fill linked list with names. I have one error could anyone fix it.
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<conio.h> #define MaxSize 30 using namespace std; struct Node { char name[MaxSize]; Node* link; }; class Q { public: void get_input(char array[]); void print_input(); private: Node* head; void display(Node* ); }; int main() { Q q; cout<<"We are goig to fill an linked list with nodes, and then switch the :"; cout<<"order between them, we will pick which wat words are go where? "; q.get_input("Joe"); q.get_input("Marry"); q.get_input("Brat"); q.get_input("Smith"); q.get_input("Guy"); q.get_input("Josh"); q.print_input(); getch(); return 0; } void Q::get_input(char array[]) { Node* temp; temp=new Node; temp->name=array[]; temp->link=head; head=temp; } void Q::print_input() { cout<<"The output is : "; display(head); } void Q::display(Node* head) { if (head=NULL) return ; else cout<<head->name<<" "; display(head->link); }
the error I have is:
44 C:\Documents and Settings\mauro\Desktop\c++\nodes- read names switched them around and display them.cpp expected primary-expression before ']' token
thx
please re-read my answer to your previous thead here. I already answered this question.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
•
•
Join Date: Jan 2007
Posts: 67
Reputation:
Solved Threads: 0
right
Got it. Fix the error but there is something else with it. Look at the code. Some trouble with nodes I believe
Got it. Fix the error but there is something else with it. Look at the code. Some trouble with nodes I believe
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<conio.h> #define MaxSize 30 using namespace std; struct Node { char name[MaxSize]; Node* link; }; class Q { public: void get_input(char array[]); void print_input(); private: Node* head; void display(Node* ); }; int main() { Q q; cout<<"We are goig to fill an linked list with nodes, and then switch the :"; cout<<"order between them, we will pick which wat words are go where? "; q.get_input("Joe"); q.get_input("Marry"); q.get_input("Brat"); q.get_input("Smith"); q.get_input("Guy"); q.get_input("Josh"); q.print_input(); getch(); return 0; } void Q::get_input(char array[]) { Node* temp; temp=new Node; strcpy(temp->name,array); temp->link=head; head=temp; } void Q::print_input() { cout<<"The output is : "; display(head); } void Q::display(Node* head) { if (head=NULL) return ; else cout<<head->name<<" "; display(head->link); }
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- help implementing singly linked list (C++)
- How to read in a sentence and insert in to linked list? (C++)
- Linked List using pointers (C++ ADT) (C++)
- Why doesn't this remove the last node in a linked list? (C++)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- Linked List (C++)
- help by sorting a simply linked list (C)
Other Threads in the C++ Forum
- Previous Thread: deleting a structure
- Next Thread: another simple question concerning nodes
Views: 1490 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






