结构体简单应用

 1 //定义一个结构体其中包括: 职工号、职工名、性别、年龄、工资、地址。 
 2 //按结构体类型定义一个结构体数组, 从键盘输入每个结构体元素所需的数据,
 3 //然后逐个输出这些元素的数据(可设数组只有三个元素)。
 4 
 5 //2017.3.5
 6 #include <stdio.h>
 7 #include <stdlib.h>
 8 #define N 10
 9 struct Employee
10 {
11     int Enum;//职工号
12     char Ename[100];//职工姓名
13     int Esex;//职工性别
14     int age;
15     float Esalary;//职工工资
16     char Eaddress[100];
17 };
18 
19 int main()
20 {
21     struct Employee Ep[3];
22     for (int i = 0; i < N;i++)
23     {
24         scanf_s("%d", &Ep[i].age);
25         scanf_s("%d", &Ep[i].Enum);
26         scanf_s("%d", &Ep[i].Esex);
27         scanf_s("%f", &Ep[i].Esalary);
28         scanf_s("%s%s", Ep[i].Ename, Ep[i].Eaddress);
29     }
30     for (int i = 0; i < N; i++)
31     {
32         printf("%d", Ep[i].age);
33         printf("%d", Ep[i].Enum);
34         printf("%d", Ep[i].Esex);
35         printf("%d", Ep[i].Esalary);
36         printf("%s,%s", Ep[i].Ename, Ep[i].Eaddress);
37     }
38     system("pause");
39     return 1;
40 }
原文地址:https://www.cnblogs.com/lanjianhappy/p/6533389.html