30 July 2010

compound literal with struct of structs in C

#include <stdio.h>
#include <stdlib.h>

typedef struct{
int hour, minute, second;
}Time;

typedef struct{
int day, month, year;
}Date;

typedef struct{
Time time;
Date date;
}DateTime;

int main(void)
{
DateTime dt = (DateTime){10, 9, 0,25, 11, 2010};
printf("%.2i:%.2i:%.2i\n", dt.time.hour, dt.time. minute, dt.time.second);
printf("%i/%i/%.2i\n", dt.date.day, dt.date.month, dt.date.year);

return 0;
}

No comments: