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

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