8

Using a structure

  1. #include <stdio.h>
  2.  
  3. typedef struct {
  4.     int dd, mm, yyyy;
  5. } date;
  6.  
  7. int main( ) {
  8.     static char *monthnames[] = {
  9.         "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  10.     };
  11.  
  12.     date d = { 25, 12, 2000 };
  13.     date *dp = &d;
  14.  
  15.     printf("%02d/%02d/%04d - ", d.dd, d.mm, d.yyyy);
  16.     printf("%d %s %d", d.dd, monthnames[d.mm-1], d.yyyy);
  17.     printf("\n");
  18.  
  19.     dp->dd = 1;
  20.     dp->mm = 1;
  21.     dp->yyyy++;
  22.  
  23.     printf("%02d/%02d/%04d - ", d.dd, d.mm, d.yyyy);
  24.     printf("%d %s %d", d.dd, monthnames[d.mm-1], d.yyyy);
  25.     printf("\n");
  26. }
$ gcc -DSTANDALONE -o adate adate.c
$ ./adate
25/12/2000 - 25 Dec 2000
01/01/2001 - 1 Jan 2001

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].