1. ## Struct Problem

Question: Write a function called clockKeeper that takes as its argument a dateAndTime structure. THe function should call the timeUpdate function, and if the time reaches midnight, the function should call the dateUpdate function to switch over to the next day. Have the function return the updated dateAndTime structure.

My attempt: please see the attached file.

Any help is much appreciated.

2. my attempt: (but the compiler is showing many errors which i couldn't seem to figure out)

Code:
```#include <stdio.h>

struct dateAndTime  clockKeeper (struct dateAndTime  dt)
{
struct time  timeUpdate (struct time  now);
struct date  dateUpdate (struct date  today);

dt.stime = timeUpdate (dt.stime);

if ( dt.stime.hour == 0  &&  dt.stime.minutes == 0  &&
dt.stime.seconds == 0 )
dt.sdate = dateUpdate (dt.sdate);

return  dt;
}

int main (void)
{
struct dateAndTime  dt1 = { { 12, 31, 2004 }, { 23, 59, 59 } };
struct dateAndTime  dt2 = { { 2,  28, 2008 }, { 23, 59, 58 } };

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour, dt1.stime.minutes, dt1.stime.seconds);

dt1 = clockKeeper (dt1);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour, dt1.stime.minutes, dt1.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n"
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n"
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

return 0;

}```

3. Originally Posted by cougarsmustangs
my attempt: (but the compiler is showing many errors which i couldn't seem to figure out)
It helps if you post them.

Code:
```mingw32-gcc.exe -Wall  -g  -pedantic -Wextra -Wall -ansi -g    -c C:\Users\Josh2\Documents\sandboxc\main.c -o obj\Debug\main.o
C:\Users\Josh2\Documents\sandboxc\main.c:6:54: error: parameter 1 ('dt') has incomplete type
C:\Users\Josh2\Documents\sandboxc\main.c:6:21: error: return type is an incomplete type
C:\Users\Josh2\Documents\sandboxc\main.c: In function 'clockKeeper':
C:\Users\Josh2\Documents\sandboxc\main.c:12:3: error: type of formal parameter 1 is incomplete
C:\Users\Josh2\Documents\sandboxc\main.c:17:5: error: type of formal parameter 1 is incomplete
C:\Users\Josh2\Documents\sandboxc\main.c:20:3: warning: 'return' with a value, in function returning void [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:6:54: warning: unused parameter 'dt' [-Wunused-parameter]
C:\Users\Josh2\Documents\sandboxc\main.c: In function 'main':
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: error: variable 'dt1' has initializer but incomplete type
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: error: extra brace group at end of initializer
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: error: (near initialization for 'dt1')
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: warning: excess elements in struct initializer [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: warning: (near initialization for 'dt1') [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: error: extra brace group at end of initializer
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: error: (near initialization for 'dt1')
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: warning: excess elements in struct initializer [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:28:10: warning: (near initialization for 'dt1') [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:28:23: error: storage size of 'dt1' isn't known
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: error: variable 'dt2' has initializer but incomplete type
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: error: extra brace group at end of initializer
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: error: (near initialization for 'dt2')
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: warning: excess elements in struct initializer [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: warning: (near initialization for 'dt2') [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: error: extra brace group at end of initializer
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: error: (near initialization for 'dt2')
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: warning: excess elements in struct initializer [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:29:10: warning: (near initialization for 'dt2') [enabled by default]
C:\Users\Josh2\Documents\sandboxc\main.c:29:23: error: storage size of 'dt2' isn't known
C:\Users\Josh2\Documents\sandboxc\main.c:49:11: error: expected ')' before 'dt2'
C:\Users\Josh2\Documents\sandboxc\main.c:73:11: error: expected ')' before 'dt2'
C:\Users\Josh2\Documents\sandboxc\main.c:29:23: warning: unused variable 'dt2' [-Wunused-variable]
C:\Users\Josh2\Documents\sandboxc\main.c:28:23: warning: unused variable 'dt1' [-Wunused-variable]
Process terminated with status 1 (0 minutes, 0 seconds)
18 errors, 12 warnings (0 minutes, 0 seconds)```
Where did you write your structure declarations? Most of the rest are here because you didn't actually declare or include the structure types in this file.

Code:
```#include <stdio.h>

struct date
{
int month;
int day;
int year;
};

struct time
{
int seconds;
int minutes;
int hour;
};

struct dateAndTime  clockKeeper (struct dateAndTime  dt)
{
struct time  timeUpdate (struct time  now);
struct date  dateUpdate (struct date  today);

dt.stime = timeUpdate (dt.stime);

if ( dt.stime.hour == 0  &&  dt.stime.minutes == 0  &&  			dt.stime.seconds == 0 )
dt.sdate = dateUpdate (dt.sdate);

return  dt;
}

int main (void)
{
struct dateAndTime  dt1 = { { 12, 31, 2004 }, { 23, 59, 59 } };
struct dateAndTime  dt2 = { { 2,  28, 2008 }, { 23, 59, 58 } };

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour, dt1.stime.minutes, dt1.stime.seconds);

dt1 = clockKeeper (dt1);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour, dt1.stime.minutes, dt1.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n"
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n"
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

return 0;

}```

5. I compiled it and its still showing errors:

Code:
```\$ vim ex9.5.c

\$ gcc ex9.5.c
ex9.5.c:17:53: error: parameter 1 ('dt') has incomplete type
ex9.5.c:17:21: error: return type is an incomplete type
ex9.5.c: In function 'clockKeeper':
ex9.5.c:28:5: warning: 'return' with a value, in function returning void [enable
d by default]
ex9.5.c: In function 'main':
ex9.5.c:33:12: error: variable 'dt1' has initializer but incomplete type
ex9.5.c:33:12: error: extra brace group at end of initializer
ex9.5.c:33:12: error: (near initialization for 'dt1')
ex9.5.c:33:12: warning: excess elements in struct initializer [enabled by defaul
t]
ex9.5.c:33:12: warning: (near initialization for 'dt1') [enabled by default]
ex9.5.c:33:12: error: extra brace group at end of initializer
ex9.5.c:33:12: error: (near initialization for 'dt1')
ex9.5.c:33:12: warning: excess elements in struct initializer [enabled by defaul
t]
ex9.5.c:33:12: warning: (near initialization for 'dt1') [enabled by default]
ex9.5.c:33:25: error: storage size of 'dt1' isn't known
ex9.5.c:34:12: error: variable 'dt2' has initializer but incomplete type
ex9.5.c:34:12: error: extra brace group at end of initializer
ex9.5.c:34:12: error: (near initialization for 'dt2')
ex9.5.c:34:12: warning: excess elements in struct initializer [enabled by defaul
t]
ex9.5.c:34:12: warning: (near initialization for 'dt2') [enabled by default]
ex9.5.c:34:12: error: extra brace group at end of initializer
ex9.5.c:34:12: error: (near initialization for 'dt2')
ex9.5.c:34:12: warning: excess elements in struct initializer [enabled by defaul
t]
ex9.5.c:34:12: warning: (near initialization for 'dt2') [enabled by default]
ex9.5.c:34:25: error: storage size of 'dt2' isn't known
ex9.5.c:37:6: error: invalid operands to binary % (have 'char *' and 'complex do
uble')
ex9.5.c:37:10: error: expected ')' before ':' token
ex9.5.c:37:10: error: stray '\' in program
ex9.5.c:37:22: warning: missing terminating " character [enabled by default]
ex9.5.c:37:10: error: missing terminating " character
ex9.5.c:51:6: error: expected ')' before 'dt2'
ex9.5.c:70:6: error: expected ')' before 'dt2'```

6. Originally Posted by cougarsmustangs
Better, but still missing type declarations.

Originally Posted by cougarsmustangs
I compiled it and its still showing errors:
ex9.5.c:17:53: error: parameter 1 ('dt') has incomplete type

Notice the type of dt
Notice that type declaration is missing.
Thus everything that depends on that declaration is "wrong".

If you still have compiler errors after correcting that, then they should be easy to figure out.

7. am i on the right track? I compiled this and its still showing pretty much the same errors
Code:
```#include <stdio.h>

int dt;

struct date
{
int day;
int month;
int year;
};

struct time
{
int seconds;
int minutes;
int hour;
};

struct dateAndTime  clockKeeper (struct dateAndTime dt)
{
struct time  timeUpdate (struct time  now);
struct date  dateUpdate (struct date  today);

dt.stime = timeUpdate (dt.stime);

if ( dt.stime.hour == 0  &&  dt.stime.minutes == 0  &&
dt.stime.seconds == 0 )
dt.sdate = dateUpdate (dt.sdate);

return  dt;
}

int main (void)

int dt1;
int dt2;

{
struct dateAndTime  dt1 = { { 12, 31, 2004 }, { 23, 59, 59 } };
struct dateAndTime  dt2 = { { 2, 28, 2008 }, { 23, 59, 58 } };

printf ("Current date and time is %.2i/%.2i/%.2i "
%.2i:%.2i:%.2i\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour,
dt1.stime.minutes, dt1.stime.seconds);

dt1 = clockKeeper (dt1);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt1.sdate.month, dt1.sdate.day, dt1.sdate.year,
dt1.stime.hour, dt1.stime.minutes, dt1.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n"
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

printf ("Current date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n",
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

dt2 = clockKeeper (dt2);

printf ("Updated date and time is %.2i/%.2i/%.2i "
"%.2i:%.2i:%.2i\n\n"
dt2.sdate.month, dt2.sdate.day, dt2.sdate.year,
dt2.stime.hour, dt2.stime.minutes, dt2.stime.seconds);

return 0;

}```