home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / STRUCT3.C < prev    next >
Text File  |  1989-11-10  |  1KB  |  50 lines

  1.                                          /* Chapter 11 - Program 3 */
  2. #include "stdio.h"
  3.  
  4. void main()
  5. {
  6. struct {
  7.    char initial;
  8.    int age;
  9.    int grade;
  10.    } kids[12],*point,extra;
  11.  
  12. int index;
  13.  
  14.    for (index = 0;index < 12;index++) {
  15.       point = kids + index;
  16.       point->initial = 'A' + index;
  17.       point->age = 16;
  18.       point->grade = 84;
  19.    }
  20.  
  21.    kids[3].age = kids[5].age = 17;
  22.    kids[2].grade = kids[6].grade = 92;
  23.    kids[4].grade = 57;
  24.  
  25.    for (index = 0;index < 12;index++) {
  26.       point = kids + index;
  27.       printf("%c is %d years old and got a grade of %d\n",
  28.              (*point).initial, kids[index].age,
  29.              point->grade);
  30.    }
  31.    extra = kids[2];               /* Structure assignment */
  32.    extra = *point;                /* Structure assignment */
  33. }
  34. /* Result of execution
  35.  
  36. A is 16 years old and got a grade of 84
  37. B is 16 years old and got a grade of 84
  38. C is 16 years old and got a grade of 92
  39. D is 17 years old and got a grade of 84
  40. E is 16 years old and got a grade of 57
  41. F is 17 years old and got a grade of 84
  42. G is 16 years old and got a grade of 92
  43. H is 16 years old and got a grade of 84
  44. I is 16 years old and got a grade of 84
  45. J is 16 years old and got a grade of 84
  46. K is 16 years old and got a grade of 84
  47. L is 16 years old and got a grade of 84
  48.  
  49. */
  50.