initial import
[staff/goc4/2018bti7061.git] / c-5-structuresFiles / examples / c-structures / structures3.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 struct user_structure{
5 int user_id;
6 char* username;
7 char* password;
8 };
9
10 typedef struct user_structure user;
11
12 int main(){
13 user u0 = {0,"abc","def"};
14
15 printf("u0: Userid= %d, username=%s and password =%s\n",u0.user_id,u0.username, u0.password);
16
17
18
19 user u1;
20
21 u1.user_id=1;
22 u1.username="bie1";
23 u1.password="foo";
24
25 printf("u1: Userid= %d, username=%s and password =%s\n",u1.user_id,u1.username, u1.password);
26
27
28 user* pu1 = &u1;
29
30 printf("pu1: Userid= %d, username=%s and password =%s\n",(*pu1).user_id,pu1->username, pu1->password);
31
32 user* list_of_users[80];
33
34
35 list_of_users[0]=&u1;
36
37
38 printf("lou[0]: Userid= %d, username=%s and password =%s\n",(*list_of_users[0]).user_id,list_of_users[0]->username, list_of_users[0]->password);
39
40 u1.user_id=2;
41
42 printf("lou[0]: Userid= %d, username=%s and password =%s\n",list_of_users[0]->user_id,list_of_users[0]->username, list_of_users[0]->password);
43
44
45 list_of_users[1]=(user*)malloc(sizeof(user));
46
47 list_of_users[1]->user_id=3;
48 list_of_users[1]->username="beo1";
49 list_of_users[1]->password="bar";
50
51 printf("lou[1]: Userid= %d, username=%s and password =%s\n",list_of_users[1]->user_id,list_of_users[1]->username, list_of_users[1]->password);
52
53 printf("%lu\n",sizeof(user));// 24
54
55 }