title: C: incomplete definition of type 'struct date' error
body: <p>i started learning C and just ran into an issue.</p>
  
  <p>I created a date ADT and would like to test it out :)</p>
  
  <p>basically, i would like to read in a string from standard input, convert it to the date and print it out on standard output.</p>
  
  <p>after compiling these files i got the following errors:</p>
  
  <pre><code>datetest.c:15:45: error: incomplete definition of type 'struct date'
    printf("Year: %d Month: %d Day: %d", d-&gt;year, d-&gt;month, d-&gt;day);
                                         ~^
  ./date.h:4:16: note: forward declaration of 'struct date'
  typedef struct date Date;
  </code></pre>
  
  <p>What am i doing wrong?</p>
  
  <p>date.c:</p>
  
  <pre><code>#include "date.h"
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  struct date {
    int day;
    int month;
    int year;
  };
  
  /*
   * date_create creates a Date structure from `datestr`
   * `datestr' is expected to be of the form "dd/mm/yyyy"
   * returns pointer to Date structure if successful,
   *         NULL if not (syntax error)
   */
  Date *date_create(char *datestr) {
    Date *d = (Date *)malloc(sizeof(Date));
    const char delimiter[2] = "/";
    char *token;
  
    if (d != NULL) {  
      token = strtok(datestr, delimiter);
      d-&gt;day = atoi(token);
      token = strtok(NULL, delimiter);
      d-&gt;month = atoi(token);
      token = strtok(NULL, delimiter);
      d-&gt;year = atoi(token);
      //printf("Day: %d Month: %d Year: %d\n", d-&gt;day, d-&gt;month, d-&gt;year);    
      //printf("Day: %p Month: %p Year: %p\n", *d-&gt;day, *d-&gt;month, *d-&gt;year);
    }
    return d;
  };
  
  /*
   * date_duplicate creates a duplicate of `d'
   * returns pointer to new Date structure if successful,
   *         NULL if not (memory allocation failure)
   */
  Date *date_duplicate(Date *d) {
    Date *dd = (Date *)malloc(sizeof(Date));
    if (dd != NULL) {
      dd-&gt;day = d-&gt;day;
      dd-&gt;month = d-&gt;month;
      dd-&gt;year = d-&gt;year;
    }
    return dd;
  };
  
  /*
   * date_compare compares two dates, returning &lt;0, 0, &gt;0 if
   * date1&lt;date2, date1==date2, date1&gt;date2, respectively
   */
  int date_compare(Date *date1, Date *date2) {
    if (date1-&gt;year &lt; date2-&gt;year)
      return -1;
    else if (date1-&gt;year &gt; date2-&gt;year)
      return 1;
    else {
      if (date1-&gt;month &lt; date2-&gt;month)
        return -1;
      else if (date1-&gt;month &gt; date2-&gt;month)
        return 1;
      else {
        if (date1-&gt;day &lt; date2-&gt;day)
      return -1;
        else if (date1-&gt;day &gt; date2-&gt;day)
      return 1;
        else
      return 0;
      }
    }
  };
  
  /*
   * date_destroy returns any storage associated with `d' to the system
   */
  void date_destroy(Date *d) {
    if (d != NULL)
      free(d);
  };
  </code></pre>
  
  <p>datetest.c:</p>
  
  <pre><code>#include "date.h"
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
    Date *d;
    char buf[1024], *s;
  
    while (fgets(buf, sizeof(buf), stdin) != NULL) {
      if (!(d = date_create(buf))) {
      fprintf(stderr, "Unable to create a date.\n");
      return -1;
      }
        printf("Year: %d Month: %d Day: %d", d-&gt;year, d-&gt;month, d-&gt;day);
    }
  }
  </code></pre>
  
  <p>date.h:</p>
  
  <pre><code>#ifndef _DATE_H_INCLUDED_
  #define _DATE_H_INCLUDED_
  
  typedef struct date Date;
  
  /*
   * date_create creates a Date structure from `datestr`
   * `datestr' is expected to be of the form "dd/mm/yyyy"
   * returns pointer to Date structure if successful,
   *         NULL if not (syntax error)
   */
  Date *date_create(char *datestr);
  
  /*
   * date_duplicate creates a duplicate of `d'
   * returns pointer to new Date structure if successful,
   *         NULL if not (memory allocation failure)
   */
  Date *date_duplicate(Date *d);
  
  /*
   * date_compare compares two dates, returning &lt;0, 0, &gt;0 if
   * date1&lt;date2, date1==date2, date1&gt;date2, respectively
   */
  int date_compare(Date *date1, Date *date2);
  
  /*
   * date_destroy returns any storage associated with `d' to the system
   */
  void date_destroy(Date *d);
  
  #endif /* _DATE_H_INCLUDED_ */
  </code></pre>