Guest User

Untitled

a guest
Jan 4th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /* Ch3-3e.c*/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. struct phone /* 結構phone的宣告 */
  6. {
  7. char phone1[15];
  8. char phone2[15];
  9. };
  10. struct label /* 結構label的宣告 */
  11. {
  12. char name[20];
  13. int age;
  14. struct phone callno;
  15. };
  16. /* 函數: 顯示結構指標的成員變數 */
  17. void showlabel(struct label *ptr)
  18. {
  19. printf("員工名牌----------\n");
  20. printf("姓名: %s\n", ptr->name);
  21. printf("年齡: %d\n", ptr->age);
  22. printf("電話: %s\n", ptr->callno.phone1);
  23. printf("手機: %s\n", ptr->callno.phone2);
  24. printf("------------------\n");
  25. }
  26. /* 主程式 */
  27. int main()
  28. {
  29. /* 宣告變數 */
  30. struct label worker;
  31. struct label *ptr;
  32. /* 將結構指標指向結構 */
  33. ptr = &worker;
  34. /* 指定結構的成員變數 */
  35. strcpy(worker.name, "陳會安");
  36. ptr->age = 30;
  37. strcpy(worker.callno.phone1, "04-8969876");
  38. strcpy(worker.callno.phone2, "0911-987654");
  39. /* 顯示結構的成員變數 */
  40. printf("姓名: %s\n", worker.name);
  41. printf("年齡: %d\n", worker.age);
  42. printf("電話: %s\n", worker.callno.phone1);
  43. printf("手機: %s\n", worker.callno.phone2);
  44. printf("\n");
  45. /* 呼叫函數 */
  46. showlabel(ptr);
  47. system("PAUSE");
  48. return 0;
  49. }
Add Comment
Please, Sign In to add comment