【代码】
#include#define N 100 struct tele { char name[100]; char mobil[100]; char fix[100]; char email[100]; }; typedef struct tele telestru; int input(telestru s[]) { int n = -1, i; printf("请按下列格式输入信息(行首输入q结束输入):n"); printf("----------------------------------------------------------------------------------------n"); printf("姓名tt移动电话tt固定电话ttemailn"); do { n++; scanf("%s", s[n].name); if (s[n].name[0] == 'q') break; scanf("%s", s[n].mobil); scanf("%s", s[n].fix); scanf("%s", s[n].email); } while (1); return n; } void print(telestru* s, int n) { int i, j; if (n > 0) { printf("请按下列格式输入信息(行首输入q结束输入):n"); printf("----------------------------------------------------------------------------------------n"); printf("姓名tt移动电话tt固定电话ttemailn"); for (i = 0; i < n; i++, s++) { printf("%-stt", s->name); printf("%-stt", s->mobil); printf("%-stt", s->fix); printf("%-sn", s->email); } } } int main() { telestru s[N]; int n; n = input(s);//输入 print(s, n);//输出 return 0; }
【注意】
定义结构体里面的字符串数组可以适当多给一些空间,一定不要把空间给得太紧凑了,不然存储会出现混乱。



