home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list11_4.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  908b  |  42 lines

  1.  /* Demonstrates stepping through an array of structures */
  2.  /* using pointer notation. */
  3.  
  4.  #include <stdio.h>
  5.  
  6.  #define MAX 4
  7.  
  8.  /* Define a structure, then declare and initialize */
  9.  /* an array of 4 structures. */
  10.  
  11.  struct part {
  12.      int number;
  13.      char name[10];
  14.  } data[MAX] = {1, "Smith",
  15.                 2, "Jones",
  16.                 3, "Adams",
  17.                 4, "Wilson"
  18.                 };
  19.  
  20.  /* Declare a pointer to type part, and a counter variable. */
  21.  
  22.  struct part *p_part;
  23.  int count;
  24.  
  25.  main()
  26.  {
  27.      /* Initialize the pointer to the first array element. */
  28.  
  29.      p_part = data;
  30.  
  31.      /* Loop through the array, incrementing the pointer */
  32.      /* with each iteration. */
  33.  
  34.      for (count = 0; count < MAX; count++)
  35.      {
  36.          printf("\nAt address %d: %d %s", p_part, p_part->number,
  37.                  p_part->name);
  38.          p_part++;
  39.      }
  40.  
  41.  }
  42.