initial import
[staff/goc4/2018bti7061.git] / c-5-structuresFiles / examples / c-structures / structures2.c
1 #include <stdio.h>
2
3 struct date{
4 int year;
5 int month;
6 int day;
7 };
8
9 struct birthdate{
10 char name[80];
11 struct date birth;
12 };
13
14
15
16 struct account {
17 int acct_no;
18 char acct_type;
19 char name[80];
20 float balance;
21 struct date lastpayment;
22 } myAccount1; /* define a variable myAccount1 from type struct account */
23
24 int main(){
25 printf("Structures, example2\n");
26
27 /* define a variable myAccount2 of type struct account */
28 struct account myAccount2;
29
30 /* Define an array containing 100 struct accounts */
31 struct account myAccountArray[100];
32
33 myAccount1.acct_no = 10;
34
35 myAccount2.acct_type ='a';
36
37 myAccountArray[0].acct_no = 9;
38
39 printf("My Account1 number=%d; type=%c; ", myAccount1.acct_no,myAccount2.acct_type);
40
41
42 static struct birthdate birthdays[]={
43 {"Emmanuel",{1960,10,24}},
44 {"Jean",{1940,1,30}},
45 {"Paul",{1930,5,10}}
46 };
47 int size_birthdays = 3;
48
49 printf("Birthdays list:\n");
50 int i;
51 for(i=0;i< size_birthdays ;i++){
52 printf("Birth of %s was on %d.%d.%d \n",
53 birthdays[i].name,
54 birthdays[i].birth.day,
55 birthdays[i].birth.month,
56 birthdays[i].birth.year);
57 }
58
59 }