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

  1.  /* Demonstrates using arrays of structures. */
  2.  
  3.  #include <stdio.h>
  4.  
  5.  /* Define a structure to hold entries. */
  6.  
  7.  struct entry {
  8.      char fname[20];
  9.      char lname[20];
  10.      char phone[10];
  11.  };
  12.  
  13.  /* Declare an array of structures. */
  14.  
  15.  struct entry list[4];
  16.  
  17.  int i;
  18.  
  19.  main()
  20.  {
  21.  
  22.      /* Loop to input data for four people. */
  23.  
  24.      for (i = 0; i < 4; i++)
  25.      {
  26.          printf("\nEnter first name: ");
  27.          scanf("%s", list[i].fname);
  28.          printf("Enter last name: ");
  29.          scanf("%s", list[i].lname);
  30.          printf("Enter phone in 123-4567 format: ");
  31.          scanf("%s", list[i].phone);
  32.      }
  33.  
  34.      /* Print two blank lines. */
  35.  
  36.      printf("\n\n");
  37.  
  38.      /* Loop to display data. */
  39.  
  40.      for (i = 0; i < 4; i++)
  41.      {
  42.          printf("Name: %s %s", list[i].fname, list[i].lname);
  43.          printf("\t\tPhone: %s\n", list[i].phone);
  44.      }
  45.  }
  46.