#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* 結構label的宣告 */
struct phone{
char phone1[10];
char phone2[10];
};
struct 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("電話1: %s\n", ptr->callno.phone1);
printf("電話2: %s\n", ptr->callno.phone2);
printf("------------------\n");
}
/* 主程式 */
int main() {
/* 宣告變數 */
struct label worker;
struct label *ptr;
/* 將結構指標指向結構 */
ptr = &worker;
/* 指定結構的成員變數 */
strcpy(worker.name, "陳會安");
ptr->age = 30;
strcpy(ptr->callno.phone1,"12345678");
strcpy(ptr->callno.phone2,"98765432");
printf("姓名: %s\n", worker.name);
printf("年齡: %d\n", worker.age);
printf("電話1: %s\n", worker.callno.phone1);
printf("電話2: %d\n", worker.callno.phone1);
/* 呼叫函數 */
showlabel(ptr);
system("PAUSE");
return 0;
}
printf("姓名: %s\n", worker.name);
回覆刪除printf("年齡: %d\n", worker.age);
you are missed the printf("電話1:...) and printf("電話2:...) in the main program.
評分: ★★★☆▲
寫太快,沒有認真看題目
回覆刪除