사용자 정의 객체로써, '.'참조로 하부로 한칸한칸 내려가면 된다.
#include <stdio.h>
// struct [형태명]
// application 형을 선언한다.
struct applications {
char xl[15];
char ppt[15];
char word[15];
};
struct office {
int no;
char com[15];
double ver;
// struct [형태명] [변수명];
// apps라는 변수를 applications형으로 선언한다.
struct applications apps;
};
int main() {
// struct [형태명] [변수명] = {구성원1, 구성원2, 구성원3 ...};
// mso라는 변수를 office 형으로 선언한다.
struct office mso = { 1, "Microsoft", 14.0, {"MSExcel","MSPowerPoint","MSWord"} };
// 'MSPowerPoint' 출력
printf("%s\n", mso.apps.ppt);
// 'MSExcel'의 세번째 글자인 'E' 출력
printf("%c\n",mso.apps.xl[2]);
// 12.31 출력
mso.ver = 12.34;
printf("%.2f\n", mso.ver);
return 0;
}
* 피시키드님에 의해서 게시물 이동되었습니다 (2024-04-26 18:49)