943,940 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1772
  • C++ RSS
Aug 15th, 2007
0

linked list

Expand Post »
Hi
I try to fill linked list with names. I have one error could anyone fix it.

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include<iostream>
  3. #include<conio.h>
  4. #define MaxSize 30
  5. using namespace std;
  6.  
  7. struct Node
  8. {
  9. char name[MaxSize];
  10. Node* link;
  11. };
  12. class Q
  13. {
  14. public:
  15. void get_input(char array[]);
  16. void print_input();
  17. private:
  18. Node* head;
  19. void display(Node* );
  20. };
  21. int main()
  22. {
  23. Q q;
  24. cout<<"We are goig to fill an linked list with nodes, and then switch the :";
  25. cout<<"order between them, we will pick which wat words are go where? ";
  26. q.get_input("Joe");
  27. q.get_input("Marry");
  28. q.get_input("Brat");
  29. q.get_input("Smith");
  30. q.get_input("Guy");
  31. q.get_input("Josh");
  32. q.print_input();
  33.  
  34. getch();
  35. return 0;
  36. }
  37. void Q::get_input(char array[])
  38. {
  39. Node* temp;
  40. temp=new Node;
  41. temp->name=array[];
  42. temp->link=head;
  43. head=temp;
  44. }
  45. void Q::print_input()
  46. {
  47. cout<<"The output is : ";
  48. display(head);
  49. }
  50.  
  51. void Q::display(Node* head)
  52. {
  53. if (head=NULL)
  54. return ;
  55. else
  56. cout<<head->name<<" ";
  57. display(head->link);
  58. }

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
Reputation Points: 20
Solved Threads: 0
Junior Poster in Training
mauro21pl is offline Offline
66 posts
since Jan 2007
Aug 15th, 2007
0

Re: linked list

please re-read my answer to your previous thead here. I already answered this question.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Aug 15th, 2007
0

Re: linked list

right
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)
  1.  
  2. #include<iostream>
  3. #include<conio.h>
  4. #define MaxSize 30
  5. using namespace std;
  6.  
  7. struct Node
  8. {
  9. char name[MaxSize];
  10. Node* link;
  11. };
  12. class Q
  13. {
  14. public:
  15. void get_input(char array[]);
  16. void print_input();
  17. private:
  18. Node* head;
  19. void display(Node* );
  20. };
  21. int main()
  22. {
  23. Q q;
  24. cout<<"We are goig to fill an linked list with nodes, and then switch the :";
  25. cout<<"order between them, we will pick which wat words are go where? ";
  26. q.get_input("Joe");
  27. q.get_input("Marry");
  28. q.get_input("Brat");
  29. q.get_input("Smith");
  30. q.get_input("Guy");
  31. q.get_input("Josh");
  32. q.print_input();
  33.  
  34. getch();
  35. return 0;
  36. }
  37. void Q::get_input(char array[])
  38. {
  39. Node* temp;
  40. temp=new Node;
  41. strcpy(temp->name,array);
  42. temp->link=head;
  43. head=temp;
  44. }
  45. void Q::print_input()
  46. {
  47. cout<<"The output is : ";
  48. display(head);
  49. }
  50.  
  51. void Q::display(Node* head)
  52. {
  53. if (head=NULL)
  54. return ;
  55. else
  56. cout<<head->name<<" ";
  57. display(head->link);
  58. }
Reputation Points: 20
Solved Threads: 0
Junior Poster in Training
mauro21pl is offline Offline
66 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: deleting a structure
Next Thread in C++ Forum Timeline: another simple question concerning nodes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC