'복합구조체'에 해당되는 글 2건

  1. 2010.07.18 복합구조체와 배열
  2. 2010.07.18 복합 구조체
Objective C/C언어 기능2010. 7. 18. 17:38


복합구조체와 배열

struct date

{

int month;

int day;

int year;

};

struct time

{

int hour;

int minutes;

int seconds;

};

struct date_and_time

{

struct date sdate;

struct time stime;

};

int i=0;

//복합 구조체의 배열 선언

struct date_and_time days[10];

for( i=0; i<10; i++ ){

days[i].sdate.month = i+1;

days[i].sdate.day = (i+1)*3;

days[i].sdate.year = 2010;

days[i].stime.hour = 20;

days[i].stime.minutes = 30 * (i+1);

days[i].stime.seconds = 30 * (i+1) - 60;

NSLog(@"%i-%i-%i %i:%i:%i", days[i].sdate.month, days[i].sdate.day, days[i].sdate.year, days[i].stime.hour, days[i].stime.minutes, days[i].stime.seconds);

}

Posted by 버터백통
Objective C/C언어 기능2010. 7. 18. 12:51

/*

구조체안에 구조체를 이룬 복합 구조체 

*/ 

//날짜 구조체 선언

struct date

{

int month;

int day;

int year;

};

//시간 구조체 선언

struct time

{

int hour;

int minutes;

int seconds;

};

//복합 구조체 선언

struct date_and_time

{

struct date sdate;

struct time stime;

};

//복합구조체를 사용할 변수

struct date_and_time today;

today.sdate.month = 6;

today.sdate.day = 9;

today.sdate.year = 2010;

today.stime.hour = 20;

today.stime.minutes = 43;

today.stime.seconds = 28;

NSLog(@"print of today : %i-%i-%i %i:%i:%i", today.sdate.month, today.sdate.day, today.sdate.year, today.stime.hour, today.stime.minutes, today.stime.seconds);

Posted by 버터백통