struct within a struct

how to single out an element of a struct within a struct.

Page 1 of 1

2 Replies - 1441 Views - Last Post: 21 December 2009 - 04:16 AM Rate Topic: -----

#1 redbloodcell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 10-February 09

struct within a struct

Posted 21 December 2009 - 02:41 AM

Hello,

Say I have two data types Time and Date defined as such:

struct Time {
int hour;
int min;
int sec; }

struct Date{
int year;
int month; 
int day;
Time time;}



to define today's date, initialize a variable today of type Date, ie. Date today; then set the elements respectively using today.year, today.month, today.day.

but how about today's time? to define 18:31:30 of today's date do i use
today.time.hour = 18;
today.time.min = 31;
today.time.sec = 30;

would that work? i realize i can just set the 3 elements of time in the Date struct but my homework requires me to use the struct Time. any help would be appreciated. thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: struct within a struct

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: struct within a struct

Posted 21 December 2009 - 02:48 AM

Looks fine to me.

Read here for confirmation
http://www.exforsys....-c-part-ii.html
Was This Post Helpful? 0
  • +
  • -

#3 redbloodcell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 10-February 09

Re: struct within a struct

Posted 21 December 2009 - 04:16 AM

View Postjanotte, on 21 Dec, 2009 - 01:48 AM, said:

Looks fine to me.

Read here for confirmation
http://www.exforsys....-c-part-ii.html


you're right! thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1