home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / SOLAR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  1.3 KB  |  49 lines

  1. /* SOLAR.C--Example from Chapter 4 of Getting Started */
  2.  
  3. #include <graphics.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. typedef struct {
  8.    char name[10];
  9.    float distance;
  10.    float radius;
  11.    int color;
  12.    int fill_type;
  13. } planet;
  14.  
  15. planet solar_system[9];
  16. planet *planet_ptr;
  17. int    planet_num;
  18.  
  19. int main()
  20. {
  21.    strcpy(solar_system[0].name,"Mercury");
  22.    solar_system[0].distance = 0.4;
  23.    solar_system[0].radius = 0.4;
  24.    solar_system[0].color = EGA_YELLOW;
  25.    solar_system[0].fill_type = EMPTY_FILL;
  26.  
  27.    planet_ptr = solar_system;
  28.    planet_ptr++;             /* Point to second planet structure */
  29.     strcpy (planet_ptr->name,"Venus");
  30.    planet_ptr->distance = 0.7;
  31.    planet_ptr->radius = 1.0;
  32.    planet_ptr->color = EGA_BROWN;
  33.    planet_ptr->fill_type = SOLID_FILL;
  34.  
  35.    planet_ptr = solar_system;         /* Reset to first element */
  36.    for (planet_num = 0; planet_num < 2; planet_num++, planet_ptr++) {
  37.       printf("\nPlanetary statistics:\n");
  38.       printf("Name: %s\n", planet_ptr->name);
  39.       printf("Distance from Sun in AU: %4.2f\n",
  40.               planet_ptr->distance);
  41.       printf("Radius in Earth radii: %4.2f\n", planet_ptr->radius);
  42.       printf("Color constant value %d\n", planet_ptr->color);
  43.       printf("Fill pattern constant value %d\n",
  44.              planet_ptr->fill_type);
  45.    }
  46.  
  47.    return 0;
  48. }
  49.