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%2FStruct_Define</id>
		<title>C/Structure/Struct Define - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FStructure%2FStruct_Define"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C/Structure/Struct_Define&amp;action=history"/>
		<updated>2026-04-17T21:33:01Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C/Structure/Struct_Define&amp;diff=128&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/Struct_Define&amp;diff=128&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/Struct_Define&amp;diff=129&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/Struct_Define&amp;diff=129&amp;oldid=prev"/>
				<updated>2010-05-25T10:22:15Z</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;==Define and use a struct==&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;
struct struct_type {&lt;br /&gt;
  int i;&lt;br /&gt;
  char ch;&lt;br /&gt;
  double d;&lt;br /&gt;
  char str[80];&lt;br /&gt;
} s;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  printf(&amp;quot;Enter an integer: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot;%d:&amp;quot;, &amp;amp;s.i);&lt;br /&gt;
  &lt;br /&gt;
  printf(&amp;quot;Enter a character: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot; %c&amp;quot;, &amp;amp;s.ch);&lt;br /&gt;
  &lt;br /&gt;
  printf(&amp;quot;Enter a floating point number: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot;%lf&amp;quot;, &amp;amp;s.d);&lt;br /&gt;
  &lt;br /&gt;
  printf(&amp;quot;Enter a string: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot;%s&amp;quot;, s.str);&lt;br /&gt;
  printf(&amp;quot;%d %c %f %s&amp;quot;, s.i, s.ch, s.d, s.str);&lt;br /&gt;
  return 0;&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;
==Define a simplest struct==&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;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  struct {&lt;br /&gt;
    int a;&lt;br /&gt;
    int b;&lt;br /&gt;
  } x, y; &lt;br /&gt;
  x.a = 10;&lt;br /&gt;
  y = x;  /* assign one structure to another */&lt;br /&gt;
  printf(&amp;quot;%d&amp;quot;, y.a);&lt;br /&gt;
  return 0;&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;
==Exercising the horse: Structure 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;
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;
void main()&lt;br /&gt;
{&lt;br /&gt;
   struct cat myCat;&lt;br /&gt;
   printf(&amp;quot;Enter the name of the cat: &amp;quot; );&lt;br /&gt;
   scanf(&amp;quot;%s&amp;quot;, myCat.name );&lt;br /&gt;
   printf(&amp;quot;How old is %s? &amp;quot;, myCat.name );&lt;br /&gt;
   scanf(&amp;quot;%d&amp;quot;, &amp;amp;myCat.age );&lt;br /&gt;
   printf(&amp;quot;How high is %s ( in hands )? &amp;quot;, myCat.name );&lt;br /&gt;
   scanf(&amp;quot;%d&amp;quot;, &amp;amp;myCat.height );&lt;br /&gt;
   printf(&amp;quot;Who is %s&amp;quot;s father? &amp;quot;, myCat.name );&lt;br /&gt;
   scanf(&amp;quot;%s&amp;quot;, myCat.father );&lt;br /&gt;
   printf(&amp;quot;Who is %s&amp;quot;s mother? &amp;quot;, myCat.name );&lt;br /&gt;
   scanf(&amp;quot;%s&amp;quot;, myCat.mother );&lt;br /&gt;
   printf(&amp;quot;\n%s is %d years old, %d hands high,&amp;quot;, myCat.name, myCat.age, myCat.height);&lt;br /&gt;
   printf(&amp;quot; and has %s and %s as parents.\n&amp;quot;, myCat.father,myCat.mother );&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How to use struct==&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;
struct student {&lt;br /&gt;
  char name[30];  &lt;br /&gt;
  float number;&lt;br /&gt;
}  student1, student2;&lt;br /&gt;
   &lt;br /&gt;
main () {&lt;br /&gt;
    &lt;br /&gt;
  struct student student3;&lt;br /&gt;
  char s1[30];&lt;br /&gt;
  float  f;&lt;br /&gt;
  scanf (&amp;quot;%s&amp;quot;, s1);&lt;br /&gt;
  scanf (&amp;quot;%f&amp;quot;, &amp;amp;f);&lt;br /&gt;
  student1.name = s1;&lt;br /&gt;
  student2.number = f;&lt;br /&gt;
    printf (&amp;quot;Name = %s \n&amp;quot;, student1.name);&lt;br /&gt;
    printf (&amp;quot;Number = %f \n&amp;quot;, student2.number);&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Pointing out the horses: allocate memory for struct==&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;   /* For malloc() */&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;
void main()&lt;br /&gt;
{&lt;br /&gt;
   struct cat *pcat[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;Do 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;
     pcat[hcount] = (struct cat*) malloc(sizeof(struct cat));&lt;br /&gt;
     printf(&amp;quot;\nEnter the name of the cat: &amp;quot; );&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, pcat[hcount]-&amp;gt;name );&lt;br /&gt;
     printf(&amp;quot;\nHow old is %s? &amp;quot;, pcat[hcount]-&amp;gt;name );&lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;pcat[hcount]-&amp;gt;age );&lt;br /&gt;
     printf(&amp;quot;\nHow high is %s ( in hands )? &amp;quot;, pcat[hcount]-&amp;gt;name );&lt;br /&gt;
     scanf(&amp;quot;%d&amp;quot;, &amp;amp;pcat[hcount]-&amp;gt;height );&lt;br /&gt;
     printf(&amp;quot;\nWho is %s&amp;quot;s father? &amp;quot;, pcat[hcount]-&amp;gt;name );&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, pcat[hcount]-&amp;gt;father );&lt;br /&gt;
     printf(&amp;quot;\nWho is %s&amp;quot;s mother? &amp;quot;, pcat[hcount]-&amp;gt;name );&lt;br /&gt;
     scanf(&amp;quot;%s&amp;quot;, pcat[hcount]-&amp;gt;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;, pcat[i]-&amp;gt;name, pcat[i]-&amp;gt;age, pcat[i]-&amp;gt;height);&lt;br /&gt;
     printf(&amp;quot; and has %s and %s as parents.&amp;quot;, pcat[i]-&amp;gt;father, pcat[i]-&amp;gt;mother);&lt;br /&gt;
     free(pcat[i]);&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 structure representing a length==&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;
#define INCHES_PER_FOOT 12&lt;br /&gt;
#define FEET_PER_YARD    3&lt;br /&gt;
struct Length&lt;br /&gt;
{&lt;br /&gt;
  unsigned int yards;&lt;br /&gt;
  unsigned int feet;&lt;br /&gt;
  unsigned int inches;&lt;br /&gt;
};&lt;br /&gt;
struct Length add(struct Length first, struct Length second);&lt;br /&gt;
void show(struct Length length);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  char answer = &amp;quot;n&amp;quot;;&lt;br /&gt;
  struct Length length;&lt;br /&gt;
  struct Length total = { 0,0,0};&lt;br /&gt;
  int i = 0;&lt;br /&gt;
  length.yards =9;&lt;br /&gt;
  length.feet = 10;&lt;br /&gt;
  length.inches = 1;&lt;br /&gt;
  total = add(total,length);&lt;br /&gt;
  show(total);&lt;br /&gt;
  printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
struct Length add(struct Length first, struct Length second)&lt;br /&gt;
{&lt;br /&gt;
  unsigned long inches = 0;&lt;br /&gt;
  struct Length sum;&lt;br /&gt;
  inches = first.inches + second.inches+&lt;br /&gt;
    INCHES_PER_FOOT*(first.feet+second.feet+FEET_PER_YARD*(first.yards+second.yards));&lt;br /&gt;
  sum.inches = inches%INCHES_PER_FOOT;&lt;br /&gt;
  sum.feet = inches/INCHES_PER_FOOT;&lt;br /&gt;
  sum.yards = sum.feet/FEET_PER_YARD;&lt;br /&gt;
  sum.feet %= FEET_PER_YARD;&lt;br /&gt;
  return sum;&lt;br /&gt;
}&lt;br /&gt;
void show(struct Length length)&lt;br /&gt;
{&lt;br /&gt;
  printf(&amp;quot;%d yards %d feet %d inches&amp;quot;, length.yards,length.feet, length.inches);&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 structure 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;
#include &amp;lt;stdio.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 MAX_NUMBERS     50&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;
struct Name read_name();               /* Read a name from the keyboard */               &lt;br /&gt;
void show(struct PhoneRecord record);  /* Output a phone record         */&lt;br /&gt;
int has_name(struct PhoneRecord record, struct Name name); /* Test for a name */&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  char answer = &amp;quot;n&amp;quot;;&lt;br /&gt;
  struct PhoneRecord records[MAX_NUMBERS];  /* Array of phone records  */&lt;br /&gt;
  struct Name aName;                        /* Stores a name           */&lt;br /&gt;
  int count = 0;                            /* Number of phone records */&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;
    records[count].name = read_name();                 /* Read 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;,records[count++].number);  /* Read the number - including spaces */&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(count&amp;lt;=MAX_NUMBERS &amp;amp;&amp;amp; tolower(answer) == &amp;quot;y&amp;quot;);&lt;br /&gt;
  /* Search the array of phone records for a number */&lt;br /&gt;
  do&lt;br /&gt;
  {&lt;br /&gt;
    printf(&amp;quot;Enter a name for which you want the number.&amp;quot;);&lt;br /&gt;
    aName =read_name();&lt;br /&gt;
    for(i = 0 ; i&amp;lt;count ; i++)&lt;br /&gt;
    {&lt;br /&gt;
      if(has_name(records[i], aName))                 /* Test for the name */&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;, records[i].number);            /* Output the number for the name */&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    if(found)                                         /* If the name was found */&lt;br /&gt;
      found = FALSE;                                  /* Reset the found flag  */&lt;br /&gt;
    else                                              /* Otherwise output message */&lt;br /&gt;
      printf(&amp;quot;No numbers found for this name.\n&amp;quot;);&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;
  for(i = 0 ; i&amp;lt;count ; i++)&lt;br /&gt;
    show(records[i]);&lt;br /&gt;
  printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
/* Function to read a name and store it in a Name structure */&lt;br /&gt;
struct Name read_name()&lt;br /&gt;
{&lt;br /&gt;
  struct Name name;&lt;br /&gt;
    printf(&amp;quot;Enter 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;
/* Function to output a record */&lt;br /&gt;
void show(struct PhoneRecord record)&lt;br /&gt;
{&lt;br /&gt;
  printf(&amp;quot;\n%s %s   %s&amp;quot;, record.name.firstname,record.name.secondname, record.number);&lt;br /&gt;
}&lt;br /&gt;
/* Function to test whether the name is the same as in a record */&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;
 &lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using a structure to record the count of occurrences of a word==&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;
  This program defines a structure that stores a word and the count of its occurrences.&lt;br /&gt;
  The structures are stored as they are created in a linked list. If you wanted the&lt;br /&gt;
  output in alphabetical order, you could insert the structures in the list to ensure&lt;br /&gt;
  that the list was ordered. Alternatively you could sort the list.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define MAX_WORD_LENGTH    31&lt;br /&gt;
#define MAX_TEXT_LENGTH 10000&lt;br /&gt;
#define TRUE                1&lt;br /&gt;
#define FALSE               0&lt;br /&gt;
/* Structure defining a count of the occurrences of a given word */&lt;br /&gt;
struct WordCounter&lt;br /&gt;
{&lt;br /&gt;
  char *word;&lt;br /&gt;
  int word_count;&lt;br /&gt;
  struct WordCounter *pNext;                        /* Pointer to the next word counter in the list */&lt;br /&gt;
};&lt;br /&gt;
/* Function prototypes */&lt;br /&gt;
void addWord(char *pWord);                          /* Adds a word to the list or updates exisiting word */&lt;br /&gt;
int is_separator(char ch);                          /* Tests for a separator character */&lt;br /&gt;
void show(struct WordCounter *pWordcounter);        /* Outputs a word and its count of occurrences */&lt;br /&gt;
struct WordCounter* createWordCounter(char *word);  /* Creates a new WordCounter structure */&lt;br /&gt;
/* Global variables */&lt;br /&gt;
struct WordCounter *pStart = NULL;                  /* Pointer to first word counter in the list */&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  char text[MAX_TEXT_LENGTH];           /* Stores input text         */&lt;br /&gt;
  char buffer[MAX_WORD_LENGTH];         /* Buffer to hold a word     */&lt;br /&gt;
  size_t i = 0;                         /* Index to text             */&lt;br /&gt;
  int len = 0 ;                         /* Word length               */&lt;br /&gt;
  struct WordCounter *pCounter = NULL;  /* Pointer to a word counter */      &lt;br /&gt;
  /* Read the text from the keyboard */&lt;br /&gt;
  printf(&amp;quot;Enter the text:\n&amp;quot;);&lt;br /&gt;
  gets(text);&lt;br /&gt;
  /* Extract the words from the text  */  &lt;br /&gt;
  while(text[i] != &amp;quot;\0&amp;quot;)&lt;br /&gt;
  {&lt;br /&gt;
    /* Skip over separators */&lt;br /&gt;
    while(is_separator(text[i]))&lt;br /&gt;
      ++i;&lt;br /&gt;
    /* It is either the end of the string or the start of a word    */&lt;br /&gt;
    /* As long as it is not the string terminator copy the character */&lt;br /&gt;
    len = 0;              /* Reset character count    */&lt;br /&gt;
    while((!is_separator(text[i])) &amp;amp;&amp;amp; (text[i] != &amp;quot;\0&amp;quot;))&lt;br /&gt;
      buffer[len++] = text[i++];&lt;br /&gt;
    if(len&amp;gt;0)               /* Check we have some characters in the word */&lt;br /&gt;
    {&lt;br /&gt;
      buffer[len] = &amp;quot;\0&amp;quot;;   /* We reached the end of a word so add terminator */&lt;br /&gt;
      addWord(buffer);      /* Add the word to the list */&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /* List the words and their counts */&lt;br /&gt;
  pCounter = pStart;&lt;br /&gt;
  while(pCounter != NULL)&lt;br /&gt;
  {&lt;br /&gt;
    show(pCounter);&lt;br /&gt;
    pCounter = pCounter-&amp;gt;pNext;&lt;br /&gt;
  }&lt;br /&gt;
  printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
  /* Free the memory that we allocated */&lt;br /&gt;
  pCounter = pStart;&lt;br /&gt;
  while(pCounter != NULL)&lt;br /&gt;
  {&lt;br /&gt;
    free(pCounter-&amp;gt;word);        /* Free space for the word */&lt;br /&gt;
    pStart = pCounter;           /* Save address of current */&lt;br /&gt;
    pCounter = pCounter-&amp;gt;pNext;  /* Move to next counter    */&lt;br /&gt;
    free(pStart);                /* Free space for current  */     &lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/* Returns TRUE if the argument is a separator character and FALSE otherwise */&lt;br /&gt;
int is_separator(char ch)&lt;br /&gt;
{&lt;br /&gt;
  /* Separators are space, comma, colon, semicolon, double quote, question mark, exclamation, and period */&lt;br /&gt;
  static char separators[] = { &amp;quot; &amp;quot; , &amp;quot;,&amp;quot;,&amp;quot;:&amp;quot; , &amp;quot;\&amp;quot;&amp;quot;, &amp;quot;?&amp;quot; , &amp;quot;!&amp;quot; , &amp;quot;.&amp;quot;};&lt;br /&gt;
  int i = 0;&lt;br /&gt;
  for(i = 0 ; i&amp;lt;sizeof separators ; i++)&lt;br /&gt;
  {&lt;br /&gt;
    if(ch == separators[i])&lt;br /&gt;
      return TRUE;&lt;br /&gt;
  }&lt;br /&gt;
  return FALSE;&lt;br /&gt;
}&lt;br /&gt;
void show(struct WordCounter *pWordcounter)&lt;br /&gt;
{&lt;br /&gt;
  /* output the word left-justified in a fixed field width followed by the count */&lt;br /&gt;
  printf(&amp;quot;\n%-30s   %5d&amp;quot;, pWordcounter-&amp;gt;word,pWordcounter-&amp;gt;word_count);&lt;br /&gt;
}&lt;br /&gt;
void addWord(char *word)&lt;br /&gt;
{&lt;br /&gt;
  struct WordCounter *pCounter = NULL;&lt;br /&gt;
  struct WordCounter *pLast = NULL;&lt;br /&gt;
  if(pStart == NULL)&lt;br /&gt;
  {&lt;br /&gt;
    pStart = createWordCounter(word);&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  /* If the word is in the list, increment its count */&lt;br /&gt;
  pCounter = pStart;&lt;br /&gt;
  while(pCounter != NULL)&lt;br /&gt;
  {&lt;br /&gt;
    if(strcmp(word, pCounter-&amp;gt;word) == 0)&lt;br /&gt;
    {&lt;br /&gt;
      ++pCounter-&amp;gt;word_count;&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    pLast = pCounter;            /* Save address of last in case we need it */&lt;br /&gt;
    pCounter = pCounter-&amp;gt;pNext;  /* Move pointer to next in the list        */&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  /* If we get to here it&amp;quot;s not in the list - so add it */&lt;br /&gt;
  pLast-&amp;gt;pNext = createWordCounter(word);&lt;br /&gt;
}&lt;br /&gt;
/* Create and returns a new WordCounter object for the argument */&lt;br /&gt;
struct WordCounter* createWordCounter(char *word)&lt;br /&gt;
{&lt;br /&gt;
  struct WordCounter *pCounter = NULL;&lt;br /&gt;
  pCounter = (struct WordCounter*)malloc(sizeof(struct WordCounter));&lt;br /&gt;
  pCounter-&amp;gt;word = (char*)malloc(strlen(word)+1);&lt;br /&gt;
  strcpy(pCounter-&amp;gt;word, word);&lt;br /&gt;
  pCounter-&amp;gt;word_count = 1;&lt;br /&gt;
  pCounter-&amp;gt;pNext = NULL;&lt;br /&gt;
  return pCounter;&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>