20.09.2015 Views

Programming in C

Kochan - ProgramminginC

Kochan - ProgramminginC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

184 Chapter 9 Work<strong>in</strong>g with Structures<br />

Program 9.6<br />

};<br />

Cont<strong>in</strong>ued<br />

<strong>in</strong>t hour;<br />

<strong>in</strong>t m<strong>in</strong>utes;<br />

<strong>in</strong>t seconds;<br />

<strong>in</strong>t ma<strong>in</strong> (void)<br />

{<br />

struct time timeUpdate (struct time now);<br />

struct time testTimes[5] =<br />

{ { 11, 59, 59 }, { 12, 0, 0 }, { 1, 29, 59 },<br />

{ 23, 59, 59 }, { 19, 12, 27 }};<br />

<strong>in</strong>t i;<br />

for ( i = 0; i < 5; ++i ) {<br />

pr<strong>in</strong>tf ("Time is %.2i:%.2i:%.2i", testTimes[i].hour,<br />

testTimes[i].m<strong>in</strong>utes, testTimes[i].seconds);<br />

testTimes[i] = timeUpdate (testTimes[i]);<br />

}<br />

pr<strong>in</strong>tf (" ...one second later it's %.2i:%.2i:%.2i\n",<br />

testTimes[i].hour, testTimes[i].m<strong>in</strong>utes, testTimes[i].seconds);<br />

}<br />

return 0;<br />

// ***** Include the timeUpdate function here *****<br />

Program 9.6 Output<br />

Time is 11:59:59 ...one second later it's 12:00:00<br />

Time is 12:00:00 ...one second later it's 12:00:01<br />

Time is 01:29:59 ...one second later it's 01:30:00<br />

Time is 23:59:59 ...one second later it's 00:00:00<br />

Time is 19:12:27 ...one second later it's 19:12:28<br />

The concept of an array of structures is a very powerful and important one <strong>in</strong> C. Make<br />

certa<strong>in</strong> you understand it fully before you move on.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!