t variable is coming up with an error from assigntime function onwards saying it must have a pointer to a struct or union type. pointers are my weakness, if anyone could explain, not just give me the answer, what i need to do to fix this that would be most helpful! cheers.
//MY TIME C FILE
#include "my_time.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct my_time_int
{
int hour;
int minute;
int second;
};
void init_my_time(my_time *t)
{
t=(my_time)malloc(sizeof(struct init_my_time*));
}
/*
* Alter hour, minute, and second
* Param h new value for hour
* Param m new value for minute
* Param s new value for second
*/
void assignTime(my_time *t, int h, int m, int s)
{
t->hour = h;
t->minute = m;
t->second = s;
}
//FOLLOWING CODE T VARIABLE HAS RED UNDERLINE ERROR SAYING EXPRESSION MUST HAVE POINTER TO STRUCT OR UNION>
char *toString(my_time t)
{
char *r = (char *)malloc(12 * sizeof(char));
if (t.hour >= 12) {
if (t.hour == 12)
sprintf(r, "%02d:%02d:%02d PM", 12, t.minute, t.second);
else
sprintf(r, "%02d:%02d:%02d PM", t.hour - 12, t.minute, t.second);
}
else {
if (t.hour == 0)
sprintf(r, "%02d:%02d:%02d AM", 12, t.minute, t.second);
else
sprintf(r, "%02d:%02d:%02d AM", t.hour, t.minute, t.second);
}
return r;
}
/*
* Find printable form of time in 24 hour mode
* Return String form of time in 24 hour mode for printing etc.
*/
char *toMilString(my_time t)
{
char *s = (char *)malloc(9 * sizeof(char));
sprintf(s, "%02d:%02d:%02d", t.hour, t.minute, t.second);
return s;
}
/*
* Find number of seconds elapsed since midnight
* Return number of seconds elapsed since midnight as int
*/
int secsSinceMidnight(my_time t)
{
return t.second + (60 * t.minute) + (60 * 60 * t.hour);
}
Header File Here:
#include <stdbool.h>
struct my_time_int;
typedef struct my_time_int *my_time;
void init_my_time(my_time *t);
void assignTime(my_time *t, int h, int m, int s);
void addTime(my_time t, double s);
char *toString(my_time t);
char *toMilString(my_time t);
bool equals(my_time this, my_time that);
bool my_timeIncHour(my_time *t);
bool my_timeIncMinute(my_time *t);
bool my_timeIncSecond(my_time *t);