嵌套结构

作者:追风剑情 发布于:2020-1-16 14:08 分类:C

示例

  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4.  
  5. #define LEN 20
  6.  
  7. const char* msgs[] =
  8. {
  9. " Thank you for the wonderful evening, ",
  10. "You certainly prove that a ",
  11. "is a special kind of guy. We must get together",
  12. "over a delicious ",
  13. " and have a few laughs"
  14. };
  15.  
  16. struct names {
  17. char first[LEN];
  18. char last[LEN];
  19. };
  20.  
  21. struct guy {
  22. struct names handle; //嵌套结构
  23. char favfood[LEN];
  24. char job[LEN];
  25. float income;
  26. };
  27.  
  28. int main(int argc, char* argv[])
  29. {
  30. // 初始化一个结构变量
  31. struct guy fellow = {
  32. { "Ewen", "Villard" },
  33. "grilled salmon",
  34. "personality coach",
  35. 68112.00
  36. };
  37.  
  38. printf("Dear %s, \n\n", fellow.handle.first);
  39. printf("%s%s.\n", msgs[0], fellow.handle.first);
  40. printf("%s%s\n", msgs[1], fellow.job);
  41. printf("%s\n", msgs[2]);
  42. printf("%s%s%s", msgs[3], fellow.favfood, msgs[4]);
  43. if (fellow.income > 150000.0)
  44. puts("!!");
  45. else if (fellow.income > 75000.0)
  46. puts("!");
  47. else
  48. puts(".");
  49. printf("\n%40s%s\n", " ", "See you soon,");
  50. printf("%40s%s\n", " ", "Shalala");
  51.  
  52. system("pause");
  53. return 0;
  54. }

运行测试

1111.png

标签: C语言

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号