Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Ch3-3e.c*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct phone /* 結構phone的宣告 */
- {
- char phone1[15];
- char phone2[15];
- };
- struct label /* 結構label的宣告 */
- {
- char name[20];
- int age;
- struct phone callno;
- };
- /* 函數: 顯示結構指標的成員變數 */
- void showlabel(struct label *ptr)
- {
- printf("員工名牌----------\n");
- printf("姓名: %s\n", ptr->name);
- printf("年齡: %d\n", ptr->age);
- printf("電話: %s\n", ptr->callno.phone1);
- printf("手機: %s\n", ptr->callno.phone2);
- printf("------------------\n");
- }
- /* 主程式 */
- int main()
- {
- /* 宣告變數 */
- struct label worker;
- struct label *ptr;
- /* 將結構指標指向結構 */
- ptr = &worker;
- /* 指定結構的成員變數 */
- strcpy(worker.name, "陳會安");
- ptr->age = 30;
- strcpy(worker.callno.phone1, "04-8969876");
- strcpy(worker.callno.phone2, "0911-987654");
- /* 顯示結構的成員變數 */
- printf("姓名: %s\n", worker.name);
- printf("年齡: %d\n", worker.age);
- printf("電話: %s\n", worker.callno.phone1);
- printf("手機: %s\n", worker.callno.phone2);
- printf("\n");
- /* 呼叫函數 */
- showlabel(ptr);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment