30 July 2010

compound literal with struct of structs in C

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

typedef struct{
int hour, minute, second;

typedef struct{
int day, month, year;

typedef struct{
Time time;
Date date;

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;

Post a Comment