C Primer Plus学习结构和其他数据形式(3)

利用嵌套结构来表示并打印出Shalala Pirosky的朋友的信息:

#include 
#define LEN 20
const char * msgs[5] = 
{
    "  Thank you for the wonderful evening, ",
    "You certainly prove that a ",
    "is a special kind of guy.We must get together",
    "over a delicious ",
    " and have a few laughs"
};
struct names {
    /*第1个结构*/
    char first[LEN];
    char last[LEN];
};
struct guy {
    //第2个结构
    struct names handle;  //嵌套结构
    char favfood[LEN];
    char job[LEN];
    float income;
};
int main(void)
{
    struct guy fellow = {
        { "Ewen", "Villard"},
        "grilled salmon",
        "personality coach",
        68112.00
    };
    printf("Dear %s, \n\n", fellow.handle.first);
    printf("%s%s.\n", msgs[0], fellow.handle.first);
    printf("%s%s\n", msgs[1], fellow.job);
    printf("%s\n", msgs[2]);
    printf("%s%s%s", msgs[3], fellow.favfood, msgs[4]);
    if (fellow.income > 150000.0)
    puts("!!");
    else if (fellow.income > 75000.0)
    puts("!");
    else
    puts(".");
    printf("\n%40s%s\n", " ", "See you soon,");
    printf("%40s%s\n", " ", "Shalala");
    return 0;
}

运行结构如下:

C Primer Plus学习结构和其他数据形式(3)_第1张图片

 

你可能感兴趣的:(c语言,学习,c++)