C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 14th, 2005, 07:54 PM
SeanJA101 SeanJA101 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 6 SeanJA101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 43 sec
Reputation Power: 0
Post Problem with Entering info into structure (using linked lists)

Hello,

I am having trouble with creating a very basic program to handle an employee record for a hospital, it is supposed to contain the employee number, the name, their department and their age.

I have been given this code so far:
-------------------------------------
PHP Code:
 typedef struct employ_rec
long int empnum;
char name[21];
char dept;
int age;
}
ListEntry;
typedef struct listnode{
ListEntry data;
struct listnode *next;
}
ListNode;
typedef struct listtype{
int count;
ListNode *head;
}
ListType;
main()
{
ListType *hospital;
hospital = (ListType *) malloc(sizeof(ListType)); 


-----------------------------------------

but I am not sure where to go with it after this, as in how to input the information and to sort it by employee number... If anyone can help, or atleast point me in the right direction I would be extreemly greatful.

Thanks,

--Sean Sandy

btw.... here is the assignment, if what I have done so far makes no sense...

http://www.trentu.ca/~rhurley/cours...pet/w05ass3.pdf

Reply With Quote
  #2  
Old March 15th, 2005, 01:58 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Regarding feeding of info:
you need to assign valuelike this :
hospital->head->data.empnum = Constant

Basically you structure is composed of substructures. In other words, each node of is a linked list by itself. This is a case of multiple dimension link list analogous to multidimensional arrays.

So for assigning "next" or pointer field of your node, it depends on you whether to form link list of link list.

Clear?

and the next node as :

Reply With Quote
  #3  
Old March 15th, 2005, 02:18 PM
SeanJA101 SeanJA101 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 6 SeanJA101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 43 sec
Reputation Power: 0
Ok, sounds good, do I use:

printf("Instert Info");
scanf("%i" num);
hospital->head->data.empnum = num;


to allow the user to input the information?

--Sean Sandy

Reply With Quote
  #4  
Old March 16th, 2005, 09:36 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by SeanJA101
Ok, sounds good, do I use:

printf("Instert Info");
scanf("%i" num);
hospital->head->data.empnum = num;


to allow the user to input the information?

--Sean Sandy


Yes, but little problem in scanf.
it should be scanf("%d",num);
else you'll be greeted by errors.
Comments on this post
SeanJA101 disagrees!

Reply With Quote
  #5  
Old March 16th, 2005, 06:54 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Off course you understand that every new employee must be added to the list, right?
I mean, it's not allways added at the hospital->blabla->data.xxx !You will have to reserve some memory space for the structure of a new employee in the process and link it to the list....

Sounds obvious...but I got the impression that somehow it was not what you where going to do!

Good Luck

ANibal.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Problem with Entering info into structure (using linked lists)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT