A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FStructure%2FStructure_Array</id>
		<title>C/Structure/Structure Array - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FStructure%2FStructure_Array"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C/Structure/Structure_Array&amp;action=history"/>
		<updated>2026-04-17T22:46:28Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C/Structure/Structure_Array&amp;diff=124&amp;oldid=prev</id>
		<title> в 14:20, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C/Structure/Structure_Array&amp;diff=124&amp;oldid=prev"/>
				<updated>2010-05-25T14:20:56Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:20, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C/Structure/Structure_Array&amp;diff=125&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C/Structure/Structure_Array&amp;diff=125&amp;oldid=prev"/>
				<updated>2010-05-25T10:22:14Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A simple mailing list example using an array of structures==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C: The Complete Reference, 4th Ed. (Paperback)&lt;br /&gt;
by Herbert Schildt&lt;br /&gt;
ISBN: 0072121246&lt;br /&gt;
Publisher: McGraw-Hill Osborne Media; 4 edition (April 26, 2000)&lt;br /&gt;
*/&lt;br /&gt;
/* A simple mailing list example using an array of structures. */&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#define MAX 100&lt;br /&gt;
struct addr {&lt;br /&gt;
  char name[30];&lt;br /&gt;
  char street[40];&lt;br /&gt;
  char city[20];&lt;br /&gt;
  char state[3];&lt;br /&gt;
  unsigned long int zip;&lt;br /&gt;
} addr_list[MAX];&lt;br /&gt;
void init_list(void), enter(void);&lt;br /&gt;
void delete(void), list(void);&lt;br /&gt;
int menu_select(void), find_free(void);&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  char choice;&lt;br /&gt;
  init_list(); /* initialize the structure array */&lt;br /&gt;
  for(;;) {&lt;br /&gt;
    choice = menu_select();&lt;br /&gt;
    switch(choice) {&lt;br /&gt;
      case 1: enter();&lt;br /&gt;
        break;&lt;br /&gt;
      case 2: delete();&lt;br /&gt;
        break;&lt;br /&gt;
      case 3: list();&lt;br /&gt;
        break;&lt;br /&gt;
      case 4: exit(0);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
/* Initialize the list. */&lt;br /&gt;
void init_list(void)&lt;br /&gt;
{&lt;br /&gt;
  register int t;&lt;br /&gt;
  for(t=0; t&amp;lt;MAX; ++t) addr_list[t].name[0] = &amp;quot;\0&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
/* Get a menu selection. */&lt;br /&gt;
int menu_select(void)&lt;br /&gt;
{&lt;br /&gt;
  char s[80];&lt;br /&gt;
  int c;&lt;br /&gt;
  printf(&amp;quot;1. Enter a name\n&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;2. Delete a name\n&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;3. List the file\n&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;4. Quit\n&amp;quot;);&lt;br /&gt;
  do {&lt;br /&gt;
    printf(&amp;quot;\nEnter your choice: &amp;quot;);&lt;br /&gt;
    gets(s);&lt;br /&gt;
    c = atoi(s);&lt;br /&gt;
  } while(c&amp;lt;0 || c&amp;gt;4);&lt;br /&gt;
  return c;&lt;br /&gt;
}&lt;br /&gt;
/* Input addresses into the list. */&lt;br /&gt;
void enter(void)&lt;br /&gt;
{&lt;br /&gt;
  int slot;&lt;br /&gt;
  char s[80];&lt;br /&gt;
  slot = find_free();&lt;br /&gt;
  if(slot==-1) {&lt;br /&gt;
    printf(&amp;quot;\nList Full&amp;quot;);&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  printf(&amp;quot;Enter name: &amp;quot;);&lt;br /&gt;
  gets(addr_list[slot].name);&lt;br /&gt;
  printf(&amp;quot;Enter street: &amp;quot;);&lt;br /&gt;
  gets(addr_list[slot].street);&lt;br /&gt;
  printf(&amp;quot;Enter city: &amp;quot;);&lt;br /&gt;
  gets(addr_list[slot].city);&lt;br /&gt;
  printf(&amp;quot;Enter state: &amp;quot;);&lt;br /&gt;
  gets(addr_list[slot].state);&lt;br /&gt;
  printf(&amp;quot;Enter zip: &amp;quot;);&lt;br /&gt;
  gets(s);&lt;br /&gt;
  addr_list[slot].zip = strtoul(s, &amp;quot;\0&amp;quot;, 10);&lt;br /&gt;
}&lt;br /&gt;
/* Find an unused structure. */&lt;br /&gt;
int find_free(void)&lt;br /&gt;
{&lt;br /&gt;
  register int t;&lt;br /&gt;
  for(t=0; addr_list[t].name[0] &amp;amp;&amp;amp; t&amp;lt;MAX; ++t) ;&lt;br /&gt;
  if(t==MAX) return -1; /* no slots free */&lt;br /&gt;
  return t;&lt;br /&gt;
}&lt;br /&gt;
/* Delete an address. */&lt;br /&gt;
void delete(void)&lt;br /&gt;
{&lt;br /&gt;
  register int slot;&lt;br /&gt;
  char s[80];&lt;br /&gt;
  printf(&amp;quot;enter record #: &amp;quot;);&lt;br /&gt;
  gets(s);&lt;br /&gt;
  slot = atoi(s);&lt;br /&gt;
  if(slot&amp;gt;=0 &amp;amp;&amp;amp; slot &amp;lt; MAX)&lt;br /&gt;
    addr_list[slot].name[0] = &amp;quot;\0&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
/* Display the list on the screen. */&lt;br /&gt;
void list(void)&lt;br /&gt;
{&lt;br /&gt;
  register int t;&lt;br /&gt;
  for(t=0; t&amp;lt;MAX; ++t) {&lt;br /&gt;
    if(addr_list[t].name[0]) {&lt;br /&gt;
      printf(&amp;quot;%s\n&amp;quot;, addr_list[t].name);&lt;br /&gt;
      printf(&amp;quot;%s\n&amp;quot;, addr_list[t].street);&lt;br /&gt;
      printf(&amp;quot;%s\n&amp;quot;, addr_list[t].city);&lt;br /&gt;
      printf(&amp;quot;%s\n&amp;quot;, addr_list[t].state);&lt;br /&gt;
      printf(&amp;quot;%lu\n\n&amp;quot;, addr_list[t].zip);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  printf(&amp;quot;\n\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Daisy chaining the horses both ways==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
struct cat&lt;br /&gt;
{&lt;br /&gt;
     int age;&lt;br /&gt;
     int height;&lt;br /&gt;
     char name[20];&lt;br /&gt;
     char father[20];&lt;br /&gt;
     char mother[20];&lt;br /&gt;
     struct cat *next;     /* Pointer to next structure         */&lt;br /&gt;
     struct cat *previous; /* Pointer to previous structure     */&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   struct cat *first = NULL;&lt;br /&gt;
   struct cat *current = NULL;&lt;br /&gt;
   struct cat *last = NULL;&lt;br /&gt;
   char test = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   for( ; ; ) {&lt;br /&gt;
     printf(&amp;quot;\nDo you want to enter details of a%s cat (Y or N)? &amp;quot;, first == NULL?&amp;quot;nother &amp;quot; : &amp;quot;&amp;quot;);&lt;br /&gt;
     scanf(&amp;quot; %c&amp;quot;, &amp;amp;test );&lt;br /&gt;
     if(tolower(test) == &amp;quot;n&amp;quot;)&lt;br /&gt;
       break;&lt;br /&gt;
     /* Allocate memory for each new cat structure */&lt;br /&gt;
     current = (struct cat*)malloc(sizeof(struct cat));&lt;br /&gt;
     if( first == NULL )&lt;br /&gt;
     {&lt;br /&gt;
       first = current;            /* Set pointer to first cat   */&lt;br /&gt;
       current-&amp;gt;previous = NULL;&lt;br /&gt;
     }&lt;br /&gt;
     else&lt;br /&gt;
     {&lt;br /&gt;
       last-&amp;gt;next = current;    /* Set next address for previous cat */&lt;br /&gt;
       current-&amp;gt;previous = last; /* Previous address for current cat */&lt;br /&gt;
     }&lt;br /&gt;
     printf(&amp;quot;\nEnter the name of the cat: &amp;quot;);&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, current -&amp;gt; name );       /* Read the cat&amp;quot;s name   */&lt;br /&gt;
     printf(&amp;quot;\nHow old is %s? &amp;quot;, current -&amp;gt; name);&lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;current -&amp;gt; age);        /* Read the cat&amp;quot;s age    */&lt;br /&gt;
     printf(&amp;quot;\nHow high is %s ( in hands )? &amp;quot;, current -&amp;gt; name);&lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;current -&amp;gt; height);     /* Read the cat&amp;quot;s height */&lt;br /&gt;
     printf(&amp;quot;\nWho is %s&amp;quot;s father? &amp;quot;, current -&amp;gt; name);&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, current -&amp;gt; father);      /* Get the father&amp;quot;s name   */&lt;br /&gt;
     printf(&amp;quot;\nWho is %s&amp;quot;s mother? &amp;quot;, current -&amp;gt; name);&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, current -&amp;gt; mother);      /* Get the mother&amp;quot;s name   */&lt;br /&gt;
     current -&amp;gt; next = NULL;   /* In case its the last cat...*/&lt;br /&gt;
     last = current;           /* Save address of last cat   */&lt;br /&gt;
   }&lt;br /&gt;
   while(current != NULL)      /* Output cat data in reverse order */&lt;br /&gt;
   {&lt;br /&gt;
     printf(&amp;quot;\n\n%s is %d years old, %d hands high,&amp;quot;,&lt;br /&gt;
               current-&amp;gt;name, current-&amp;gt;age, current-&amp;gt;height);&lt;br /&gt;
     printf(&amp;quot; and has %s and %s as parents.&amp;quot;, current-&amp;gt;father,&lt;br /&gt;
                                            current-&amp;gt;mother);&lt;br /&gt;
     last = current;      /* Save pointer to enable memory to be freed */&lt;br /&gt;
     current = current-&amp;gt;previous; /* current points to previous in list */&lt;br /&gt;
     free(last);                 /* Free memory for the cat we output */&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Exercising the horses: Structure array declaration==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
struct cat&lt;br /&gt;
{&lt;br /&gt;
     int age;&lt;br /&gt;
     int height;&lt;br /&gt;
     char name[20];&lt;br /&gt;
     char father[20];&lt;br /&gt;
     char mother[20];&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   struct cat myCat[50];&lt;br /&gt;
   int hcount = 0;&lt;br /&gt;
   int i = 0;&lt;br /&gt;
   char test = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   for(hcount = 0; hcount &amp;lt; 50 ; hcount++ )&lt;br /&gt;
   {&lt;br /&gt;
     printf(&amp;quot;\nDo you want to enter details of a%s cat (Y or N)? &amp;quot;, hcount?&amp;quot;nother &amp;quot; : &amp;quot;&amp;quot; );&lt;br /&gt;
     scanf(&amp;quot; %c&amp;quot;, &amp;amp;test );&lt;br /&gt;
     if(tolower(test) == &amp;quot;n&amp;quot;)&lt;br /&gt;
       break;&lt;br /&gt;
     printf(&amp;quot;\nEnter the name of the cat: &amp;quot; );&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, myCat[hcount].name );&lt;br /&gt;
     printf(&amp;quot;\nHow old is %s? &amp;quot;, myCat[hcount].name );&lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;myCat[hcount].age );&lt;br /&gt;
     printf(&amp;quot;\nHow high is %s ( in hands )? &amp;quot;, myCat[hcount].name );&lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;myCat[hcount].height );&lt;br /&gt;
     printf(&amp;quot;\nWho is %s&amp;quot;s father? &amp;quot;, myCat[hcount].name );&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, myCat[hcount].father );&lt;br /&gt;
     printf(&amp;quot;\nWho is %s&amp;quot;s mother? &amp;quot;, myCat[hcount].name );&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, myCat[hcount].mother );&lt;br /&gt;
   }&lt;br /&gt;
   for (i = 0 ; i &amp;lt; hcount ; i++ )&lt;br /&gt;
   {&lt;br /&gt;
     printf(&amp;quot;\n\n%s is %d years old, %d hands high,&amp;quot;,myCat[i].name, myCat[i].age, myCat[i].height);&lt;br /&gt;
     printf(&amp;quot; and has %s and %s as parents.&amp;quot;, myCat[i].father,myCat[i].mother );&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using a linked list of structures representing a person&amp;quot;s name==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Beginning C, Third Edition&lt;br /&gt;
 By Ivor Horton&lt;br /&gt;
 ISBN: 1-59059-253-0&lt;br /&gt;
 Published: Apr 2004&lt;br /&gt;
 Publisher: apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
   You could link the PhoneRecord structures in a list by adding a pointer member.&lt;br /&gt;
   I chose to define a Node structure that is a node in a linked list. Each Node &lt;br /&gt;
   structure will contain a pointer to a PhoneRecord structure and a pointer to&lt;br /&gt;
   the next Node structure. Memory for Node and PhoneRecord structures are allocated&lt;br /&gt;
   dynamically. You could extend this to allocate memory for names and numbers too.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
#define FIRST_NAME_LEN  31&lt;br /&gt;
#define SECOND_NAME_LEN 51&lt;br /&gt;
#define NUMBER_LEN      16&lt;br /&gt;
#define TRUE             1&lt;br /&gt;
#define FALSE            0&lt;br /&gt;
/* Structure defining a name */&lt;br /&gt;
struct Name&lt;br /&gt;
{&lt;br /&gt;
  char firstname[FIRST_NAME_LEN];&lt;br /&gt;
  char secondname[SECOND_NAME_LEN];&lt;br /&gt;
};&lt;br /&gt;
/* Structure defining a phone record */&lt;br /&gt;
struct PhoneRecord&lt;br /&gt;
{&lt;br /&gt;
  struct Name name;&lt;br /&gt;
  char number[NUMBER_LEN];&lt;br /&gt;
};&lt;br /&gt;
/* Structure defining a node in a linked list of PhoneRecord structures */&lt;br /&gt;
struct Node&lt;br /&gt;
{&lt;br /&gt;
  struct PhoneRecord *pRecord;     /* Pointer to a PhoneRecord structure   */&lt;br /&gt;
  struct Node *pNext;              /* Pointer to the next node in the list */&lt;br /&gt;
};&lt;br /&gt;
struct Name read_name();                /* Read a name from the keyboard      */               &lt;br /&gt;
void show(struct PhoneRecord *pRecord); /* Output a phone record              */&lt;br /&gt;
int has_name(struct PhoneRecord record, struct Name name); /* Test for a name */&lt;br /&gt;
struct Node* create_node();             /* Create a new list node             */&lt;br /&gt;
struct PhoneRecord* create_record();    /* Create a new phone record          */&lt;br /&gt;
void insert_node(struct Node *pNode);   /* Insert a node in the list          */&lt;br /&gt;
int compare_records(struct PhoneRecord *pFirst, struct PhoneRecord *pSecond);  /* Compare records */&lt;br /&gt;
int compare_names(struct Name first, struct Name second); /* Compare two names                     */&lt;br /&gt;
void list_numbers(struct Name name);    /* List all numbers for a Name structure */&lt;br /&gt;
struct Node *pStart = NULL;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  char answer = &amp;quot;n&amp;quot;;&lt;br /&gt;
  struct Node *pNode = NULL;                /* Pointer to a list node              */&lt;br /&gt;
  struct PhoneRecord *pRecord = NULL;       /* Pointer to a PhoneRecord structure  */&lt;br /&gt;
  int found = FALSE;                        /* Records when a name has been found  */&lt;br /&gt;
  int i = 0;                                /* Loop control variable               */&lt;br /&gt;
 &lt;br /&gt;
  /* Read an arbitrary number of phone records from the keyboard */  &lt;br /&gt;
  do&lt;br /&gt;
  {&lt;br /&gt;
    insert_node(create_node());      /* Create and insert new node */&lt;br /&gt;
    printf(&amp;quot;Do you want to enter another(y or n)?: &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot; %c&amp;quot;, &amp;amp;answer);&lt;br /&gt;
  }while(tolower(answer) == &amp;quot;y&amp;quot;);&lt;br /&gt;
  /* Search the list of phone records for a number */&lt;br /&gt;
  do&lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;\nEnter a name for which you want the number.&amp;quot;);&lt;br /&gt;
    list_numbers(read_name());&lt;br /&gt;
    printf(&amp;quot;Do you want to search for another (y or n)? &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot; %c&amp;quot; , &amp;amp;answer);&lt;br /&gt;
  }while(tolower(answer) == &amp;quot;y&amp;quot;);&lt;br /&gt;
  /* List all the records in the linked list */&lt;br /&gt;
  pNode = pStart;&lt;br /&gt;
  do&lt;br /&gt;
  {&lt;br /&gt;
    show(pNode-&amp;gt;pRecord);&lt;br /&gt;
  }while((pNode = pNode-&amp;gt;pNext) != 0);&lt;br /&gt;
  printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
  /* Don&amp;quot;t forget to free the memory! */&lt;br /&gt;
  pNode = pStart;&lt;br /&gt;
  do&lt;br /&gt;
  {&lt;br /&gt;
    free(pNode-&amp;gt;pRecord);    /* Free memory for the record from the current node */&lt;br /&gt;
    pStart = pNode;          /* Save current node address                        */&lt;br /&gt;
    pNode = pNode-&amp;gt;pNext;    /* Get next node address                            */&lt;br /&gt;
    free(pStart);            /* Free memory for the current node                 */&lt;br /&gt;
  }while((pNode = pNode-&amp;gt;pNext) != 0);&lt;br /&gt;
}&lt;br /&gt;
/* Read a name from the keyboard and store in a structure */&lt;br /&gt;
struct Name read_name()&lt;br /&gt;
{&lt;br /&gt;
  unsigned long inches = 0;&lt;br /&gt;
  struct Name name;&lt;br /&gt;
    printf(&amp;quot;\nEnter a first name: &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot; %s&amp;quot;, &amp;amp;name.firstname);&lt;br /&gt;
    printf(&amp;quot;Enter a second name: &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot; %s&amp;quot;, &amp;amp;name.secondname);&lt;br /&gt;
  return name;&lt;br /&gt;
}&lt;br /&gt;
/* Output a record */&lt;br /&gt;
void show(struct PhoneRecord *pRecord)&lt;br /&gt;
{&lt;br /&gt;
  printf(&amp;quot;\n%s %s   %s&amp;quot;, pRecord-&amp;gt;name.firstname, pRecord-&amp;gt;name.secondname, pRecord-&amp;gt;number);&lt;br /&gt;
}&lt;br /&gt;
int has_name(struct PhoneRecord record, struct Name name)&lt;br /&gt;
{&lt;br /&gt;
  return (strcmp(name.firstname, record.name.firstname)==0 &amp;amp;&amp;amp; strcmp(name.secondname, record.name.secondname)==0);&lt;br /&gt;
}&lt;br /&gt;
/* Create a new list node */&lt;br /&gt;
struct Node* create_node()&lt;br /&gt;
{&lt;br /&gt;
  struct Node *pNode = NULL;                         /* Pointer to the new node                 */&lt;br /&gt;
  pNode = (struct Node*)malloc(sizeof(struct Node)); /* Allocate memory for node                */&lt;br /&gt;
  pNode-&amp;gt;pNext = NULL;                               /* No next node yet                        */&lt;br /&gt;
  pNode-&amp;gt;pRecord = create_record();                  /* Create record and store address in node */&lt;br /&gt;
  return pNode;&lt;br /&gt;
}&lt;br /&gt;
/* Create a new phone record    */&lt;br /&gt;
struct PhoneRecord* create_record() &lt;br /&gt;
{&lt;br /&gt;
  struct PhoneRecord *pRecord = NULL;             /* Pointer to the new record */&lt;br /&gt;
  pRecord = (struct PhoneRecord*)malloc(sizeof(struct PhoneRecord)); /* Allocate memory */&lt;br /&gt;
  pRecord-&amp;gt;name = read_name();                    /* Read the name             */      &lt;br /&gt;
  /* Get the number for the name */&lt;br /&gt;
  printf(&amp;quot;Enter the number for this name: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot; %[ 0123456789]&amp;quot;,pRecord-&amp;gt;number);       /* Read the number - including spaces */&lt;br /&gt;
  return pRecord;                                 /* Return the address of the record   */&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
  Compare two PhoneRecord structures&lt;br /&gt;
  Returns -1 if the name for the first is &amp;lt; name for the second&lt;br /&gt;
  Returns  0 if the name for the first is equal to the name for the second&lt;br /&gt;
  Returns +1 if the name for the first is &amp;gt; name for the second&lt;br /&gt;
*/&lt;br /&gt;
int compare_records(struct PhoneRecord *pFirst, struct PhoneRecord *pSecond)&lt;br /&gt;
{&lt;br /&gt;
  return compare_names(pFirst-&amp;gt;name, pSecond-&amp;gt;name);&lt;br /&gt;
}&lt;br /&gt;
/* Compare two names&lt;br /&gt;
  Returns -1 if the  first is &amp;lt; the second&lt;br /&gt;
  Returns  0 if the first is equal to tthe second&lt;br /&gt;
  Returns +1 if the first is &amp;gt;  the second&lt;br /&gt;
  The comparison is by second name. If second names are equal,&lt;br /&gt;
  first names are compared.&lt;br /&gt;
*/&lt;br /&gt;
int compare_names(struct Name first, struct Name second)&lt;br /&gt;
{&lt;br /&gt;
  int result = 0;&lt;br /&gt;
  result = strcmp(first.secondname,second.secondname);&lt;br /&gt;
  return (result != 0 ? result : strcmp(first.firstname,second.firstname));&lt;br /&gt;
}&lt;br /&gt;
/* Insert a node into the list */&lt;br /&gt;
void insert_node(struct Node *pNode)&lt;br /&gt;
{&lt;br /&gt;
  struct Node *pCurrent = NULL;&lt;br /&gt;
  struct Node *pPrevious = NULL;&lt;br /&gt;
  struct Node *pTemp = NULL;&lt;br /&gt;
  /* Check for empty list */&lt;br /&gt;
  if(pStart == NULL)&lt;br /&gt;
  {&lt;br /&gt;
    pStart = pNode;   /* Store address of the node as the start node */&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  /* Find position to insert the new node */&lt;br /&gt;
  pCurrent = pStart;&lt;br /&gt;
  while(pCurrent != NULL)&lt;br /&gt;
  {&lt;br /&gt;
    if(compare_records(pNode-&amp;gt;pRecord, pCurrent-&amp;gt;pRecord) &amp;lt;= 0)&lt;br /&gt;
    {                          /* New node goes before current list node */&lt;br /&gt;
      pNode-&amp;gt;pNext = pCurrent; /* Set new node next pointer to current   */&lt;br /&gt;
      if(pPrevious == NULL)    /* If pCurrent is the first node          */&lt;br /&gt;
      {                        &lt;br /&gt;
        pNode-&amp;gt;pNext = pStart; /* New node next pointer points to current */&lt;br /&gt;
        pStart = pNode;        /* New node is the first node              */&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {                           /* Otherwise... */&lt;br /&gt;
        pPrevious-&amp;gt;pNext = pNode; /* Previous node next pointer points to new node */&lt;br /&gt;
        pNode-&amp;gt;pNext = pCurrent;  /* New node next pointer points to current       */&lt;br /&gt;
      }&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    pPrevious = pCurrent;         /* Previous node will be the current node */&lt;br /&gt;
    pCurrent = pCurrent-&amp;gt;pNext;   /* Current node is now the next node      */   &lt;br /&gt;
  }&lt;br /&gt;
  /* If we reach here, add pNode to the end */&lt;br /&gt;
  pPrevious-&amp;gt;pNext = pNode;&lt;br /&gt;
}&lt;br /&gt;
/* List the numbers for a name */&lt;br /&gt;
void list_numbers(struct Name name)&lt;br /&gt;
{&lt;br /&gt;
  struct Node *pNode = NULL;&lt;br /&gt;
  int found = FALSE;&lt;br /&gt;
  int result = 0;&lt;br /&gt;
  /* Go through the list comparing names */&lt;br /&gt;
  pNode = pStart;&lt;br /&gt;
  while(pNode != NULL)&lt;br /&gt;
  {&lt;br /&gt;
    result = compare_names(name, pNode-&amp;gt;pRecord-&amp;gt;name);&lt;br /&gt;
    if(result == 0)&lt;br /&gt;
    {&lt;br /&gt;
      if(!found)                                    /* If this is the first time      */&lt;br /&gt;
      {&lt;br /&gt;
        found = TRUE;                               /* Reset found flag               */&lt;br /&gt;
        printf(&amp;quot;The numbers for this name are:\n&amp;quot;); /* and output the heading         */&lt;br /&gt;
      }&lt;br /&gt;
      printf(&amp;quot;%s\n&amp;quot;, pNode-&amp;gt;pRecord-&amp;gt;number);       /* Output the number for the name */&lt;br /&gt;
    }&lt;br /&gt;
   else if(result &amp;lt; 0)                              /* If name comes before current   */&lt;br /&gt;
      break;                                        /* we are done                    */&lt;br /&gt;
    pNode = pNode-&amp;gt;pNext;                           /* Otherwise move to next node    */&lt;br /&gt;
  }&lt;br /&gt;
  if(!found)                                         /* If the name was not found */&lt;br /&gt;
    printf(&amp;quot;No numbers found for this name.\n&amp;quot;);     /* Say so                    */&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>