The Open Source Swiss Army Knife

/code/c/dataStructures_c/
/code/c/dataStructures_c/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /dataStructures_c 
Permalink: list11_3.c
Title: an array of structures
article options : please login   |  raw source view  

 /* Demonstrates using arrays of structures. */

 #include <stdio.h>

 /* Define a structure to hold entries. */

 struct entry {
     char fname[20];
     char lname[20];
     char phone[10];
 };

 /* Declare an array of structures. */

 struct entry list[4];

 int i;

 main()
 {

     /* Loop to input data for four people. */

     for (i = 0; i < 4; i++)
     {
         printf("\nEnter first name: ");
         scanf("%s", list[i].fname);
         printf("Enter last name: ");
         scanf("%s", list[i].lname);
         printf("Enter phone in 123-4567 format: ");
         scanf("%s", list[i].phone);
     }

     /* Print two blank lines. */

     printf("\n\n");

     /* Loop to display data. */

     for (i = 0; i < 4; i++)
     {
         printf("Name: %s %s", list[i].fname, list[i].lname);
         printf("\t\tPhone: %s\n", list[i].phone);
     }
 }

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top