1
0

friend.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // friend.c -- example of a nested structure
  2. #include <stdio.h>
  3. #define LEN 20
  4. const char * msgs[5] =
  5. {
  6. " Thank you for the wonderful evening, ",
  7. "You certainly prove that a ",
  8. "is a special kind of guy. We must get together",
  9. "over a delicious ",
  10. " and have a few laughs"
  11. };
  12. struct names { // first structure
  13. char first[LEN];
  14. char last[LEN];
  15. };
  16. struct guy { // second structure
  17. struct names handle; // nested structure
  18. char favfood[LEN];
  19. char job[LEN];
  20. float income;
  21. };
  22. int main(void)
  23. {
  24. struct guy fellow = { // initialize a variable
  25. { "Ewen", "Villard" },
  26. "grilled salmon",
  27. "personality coach",
  28. 68112.00
  29. };
  30. printf("Dear %s, \n\n", fellow.handle.first);
  31. printf("%s%s.\n", msgs[0], fellow.handle.first);
  32. printf("%s%s\n", msgs[1], fellow.job);
  33. printf("%s\n", msgs[2]);
  34. printf("%s%s%s", msgs[3], fellow.favfood, msgs[4]);
  35. if (fellow.income > 150000.0)
  36. puts("!!");
  37. else if (fellow.income > 75000.0)
  38. puts("!");
  39. else
  40. puts(".");
  41. printf("\n%40s%s\n", " ", "See you soon,");
  42. printf("%40s%s\n", " ", "Shalala");
  43. return 0;
  44. }