《C primer plus》Chapter 14.4

# include <stdio.h>
# include <string.h>
#define LEN 10
struct name
{
    char fname[LEN];
    char mname[LEN];
    char lname[LEN];
};
struct insure
{
    int number;
    struct name person;
};
int main(void)
{
    struct insure guy[5]=
    {
        {1111,{"Jason","David","Bourne"}},
        {2222,{"Michael",'\0',"Jordan"}},
        {3333,{"Kevin","Reaper","Durant"}},
        {4444,{"LeBorn","Emperor","James"}},
        {5555,{"Kobe","Mamba","Byrant"}}
    };
    int i;
    for(i=0;i<5;i++)
    {
        printf("A:\n");
        show(&guy[i]);
        printf("B:\n");
        show1(guy[i]);
    }
    return 0;
}
void show(const struct insure *st)
{
    if(st->person.mname[0]!='\0')
        printf("%s, %s %c. -- %d\n",st->person.fname,st->person.lname,st->person.mname[0],st->number);
    else
        printf("%s, %s --%d\n",st->person.fname,st->person.lname,st->number);
}
void show1(struct insure st)
{
    if(st.person.mname[0]!='\0')
        printf("%s, %s %c. -- %d\n",st.person.fname,st.person.lname,st.person.mname[0],st.number);
    else
        printf("%s, %s -- %d\n",st.person.fname,st.person.lname,st.number);
}

猜你喜欢

转载自blog.csdn.net/Jason6620/article/details/79451415