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

  1.                                         /* Chapter 11 - Program 2 */
  2. #include "stdio.h"
  3.  
  4. void main()
  5. {
  6. struct {
  7.    char initial;
  8.    int age;
  9.    int grade;
  10.    } kids[12];
  11.  
  12. int index;
  13.  
  14.    for (index = 0;index < 12;index++) {
  15.       kids[index].initial = 'A' + index;
  16.       kids[index].age = 16;
  17.       kids[index].grade = 84;
  18.    }
  19.  
  20.    kids[3].age = kids[5].age = 17;
  21.    kids[2].grade = kids[6].grade = 92;
  22.    kids[4].grade = 57;
  23.  
  24.    kids[10] = kids[4];               /* Structure assignment  */
  25.  
  26.    for (index = 0;index < 12;index++)
  27.       printf("%c is %d years old and got a grade of %d\n",
  28.              kids[index].initial, kids[index].age,
  29.              kids[index].grade);
  30. }
  31.  
  32.  
  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. E is 16 years old and got a grade of 57
  47. L is 16 years old and got a grade of 84
  48.  
  49. */
  50.