Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone help me create a good example to learn structures? 1

Status
Not open for further replies.

Rmcta

Technical User
Nov 1, 2002
478
US
I understand that I can use structures to declare a group of variables of different data type:

struct acquaintance{
char name[10];
int year_met;
char activity_group:
};

But how do I proceed now? To learn structures I wish to do the following:

With a printf I ask the user name, year_met, activity_group. Example:

Ann 1992 dancing
Helen 1994 work
Bob 1881 skating

Then I want to create a function that calculates for how many years I have known the person, so I can learn how to pass structures to functions.

I don't know if this is a good example but I really need to learn structures and don't know how to create a good example that includes structures, arrays, pointers and functions.

Can someone guide me through this subject?

Thank you
 
You can include and use structures, arrays, pointers and functions (and recursion, and dynamic storage too;) on a classic binary tree implementation.
Add struct acquaintance* pleft, *pright; members in your declaration - use, for example:
Code:
typedef struct acquaintance
{
   struct acquaintance* pleft, *pright;
   char name[10];       /* or more, use #define NLEN  */
   int  year_met;
   char activity_group: /* better use int or short... */
} Node;
Read about a binary search in any (school level) book (or in Knuth's "Art of Programming", or search INET;).
Pass pointer to a structure, not a structure (by value) via function parameters - that's all...
It's a very instuctive task...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top