8
Using a structure
- #include <stdio.h>
- typedef struct {
- int dd, mm, yyyy;
- } date;
- int main( ) {
- static char *monthnames[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
- };
- date d = { 25, 12, 2000 };
- date *dp = &d;
- printf("%02d/%02d/%04d - ", d.dd, d.mm, d.yyyy);
- printf("%d %s %d", d.dd, monthnames[d.mm-1], d.yyyy);
- printf("\n");
- dp->dd = 1;
- dp->mm = 1;
- dp->yyyy++;
- printf("%02d/%02d/%04d - ", d.dd, d.mm, d.yyyy);
- printf("%d %s %d", d.dd, monthnames[d.mm-1], d.yyyy);
- printf("\n");
- }
$ gcc -DSTANDALONE -o adate adate.c
$ ./adate
25/12/2000 - 25 Dec 2000
01/01/2001 - 1 Jan 2001
Comments