结构体数组:实现简易通讯录
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define NUM 3 5 6 struct person 7 { 8 char name[20]; 9 char phone[10]; 10 }; 11 12 void main() 13 { 14 struct person man[NUM]; 15 int i; 16 17 for(i = 0; i<NUM; i++) 18 { 19 printf("input name:\n"); 20 gets(man[i].name); 21 printf("input phone:\n"); 22 gets(man[i].phone); 23 } 24 printf("\tname\t\t\t\t\t\tphone\n"); 25 26 for(i = 0; i<NUM; i++) 27 { 28 printf("%20s\t\t\t%20s\n", man[i].name, man[i].phone); 29 } 30 system("pause"); 31 }