2 Replies - 803 Views - Last Post: 30 June 2009 - 07:56 PM Rate Topic: -----

#1 halihali   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-May 09

help! Array of Struct in Struct

Posted 30 June 2009 - 01:33 PM

My code:
struct studen{
			  char name[20];
			  char ID[20];
			  };
struct node{
			student data[50];
			node*next;
			};
typedef struct node*pnode;
void inputstudent(pnode h, student x,int number_studen);
void outstudent(pnode h);
void outlist(pnode h)
{
	 pnode p;
	 p=h;
	 if(p==NULL)
	 cout<<"List is empty";
	 else
		 {
				 while(p!=NULL)
				 {
						 outstudent(p->data[50]); 
						 p=p->next;
							   
				 }
		 }
 }


i don't know do at --> outstudent(p->data[50]) error!
please, help me. thanks

This post has been edited by halihali: 30 June 2009 - 01:36 PM


Is This A Good Question/Topic? 0
  • +

Replies To: help! Array of Struct in Struct

#2 Notorion   User is offline

  • D.I.C Regular

Reputation: 35
  • View blog
  • Posts: 378
  • Joined: 17-February 09

Re: help! Array of Struct in Struct

Posted 30 June 2009 - 01:55 PM

Alright, I think you have set your second struct up incorreclty

The point of a linked list is to have it dynamic, not to create an array of students in each struct. Rather you will create 50 structs that hold 1 student each, and are then all linked to each other.

so, to the corrected code (to start you off)
struct student{
			  char name[20];
			  char ID[20];
			  };
struct node{
			student data;
			node*next;
			};




So with this setup, you can now think of if you have a whole list of students you will visualize it something like this.

------------------------------------
1rst Student:
name (character array)
id (character array)
next (a pointer to the 2nd student)
-----------------------------------
2nd Student:
name (character array)
id (character array)
next (a pointer to the 3rd student)
----------------------------------
3rd Student
Was This Post Helpful? 0
  • +
  • -

#3 halihali   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-May 09

Re: help! Array of Struct in Struct

Posted 30 June 2009 - 07:56 PM

Thank you very much! about your contruction.
So, If i want create One Array have maximum 50 part, each part is one list Student!
I should do it ....?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1