Using arrays of structures. - C Structure

C examples for Structure:Structure Value

Description

Using arrays of structures.

Demo Code

#include <stdio.h>

struct entry {/*from  ww w .  j  av a2s .c om*/
    char fname[20];
    char lname[20];
    char phone[10];
};

struct entry list[4];

int i;

int main( void )
{
    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);
    }

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

    return 0;
}

Result


Related Tutorials