#include <stdio.h>
#define LEN 20
struct names{
char first[LEN];
char last[LEN];
};
struct guy{
struct names handle;
char favfood[LEN];
char job[LEN];
float income;
};
struct people{
struct names handle;
char favfood[LEN];
char job[LEN];
float income;
int (*showinfo2)(struct people *him);
};
int show2(struct people *him){
// 用点还是->,是由这个前面是什么东西决定。如果它是指针,就用->,否则就用.
printf("%s, %s, %s, %s, %.2f \n", him->handle.first, him->handle.last, him->favfood, him->job, him->income);
// printf("%s, %s, %2f", him->favfood, him->job, him->income);
// printf(" %s, %s, %f", him.favfood, him.job, him.income);
}
int show(struct guy *him){
// 用点还是->,是由这个前面是什么东西决定。如果它是指针,就用->,否则就用.
printf("%s, %s, %s, %s, %.2f \n", him->handle.first, him->handle.last, him->favfood, him->job, him->income);
// printf("%s, %s, %2f", him->favfood, him->job, him->income);
// printf(" %s, %s, %f", him.favfood, him.job, him.income);
}
int main(void){
struct guy fellow[2]={
{
{"Even" , "Villard"},
"tomato",
"testing",
12000.22
},
{
{"first" , "second"},
"no"
"coding",
120.12
},
};
struct guy *him;
printf("address %p, %p \n", &fellow[0], &fellow[1]);
him = &fellow[0];
show(him);
him++;
show(him);
struct people pp={
.handle = {"p1", "p2"},
.favfood = "nothing",
.job = "dance",
.income = 3333300.22
};
show(&pp);
pp.showinfo2 = show2;
pp.showinfo2(&pp);
return 0;
}