Build a time struct for current time in UTC I'm learning about time structs. Without assigning either in code or input routines I want the current time. Please help me refactor this, if it should be. 

This code just tries to make a time struct with the current UTC time. How am I doing?

// better_current_gmtime_struct_builder.c
// compile with :
// gcc -Wall -g better_current_time_struct_builder.c -o better_current_time_struct_builder

#include &lt;time.h&gt;
#include &lt;stdio.h&gt;

/* function declarations */
void print_struct_parts(struct tm* t);

int main()
{

    time_t now;

    /* set the time for now */
    now = time( NULL ); /* NULL is a control character */

    /* set up time ponter */
    struct tm *tp;
    tp = gmtime(&amp;now);

    /* quick check of time expected */  
    printf("%s\n", asctime(tp));

    /* assign the current time struct from the time pointer */
    struct tm t = *tp;

    /* print the parts */
    print_struct_parts(&amp;t);
    return 0;   
}

/* check the struct parts */
void print_struct_parts(struct tm* t)
{
    printf ("%i\n", t-&gt;tm_wday);
    printf ("%i\n", t-&gt;tm_mon);
    printf ("%i\n", t-&gt;tm_mday);
    printf ("%i\n", t-&gt;tm_hour);
    printf ("%i\n", t-&gt;tm_min);
    printf ("%i\n", t-&gt;tm_sec);
    printf ("%i\n", t-&gt;tm_year);
}
Being brutally honest with you: your comments are useless. All of them could be erased. In special, this one is also misleading:


now = time( NULL ); /* NULL is a control character */



Wut? No NULL is not a control character. You can pass a time_t pointer to time() and get the output written to the given variable, or you can pass NULL and get the output from the returned value. It has nothing to do with 'control characters', whatever that means.

Just yesterday I answered this question that had the same problem with noisy comments. I'll quote my own answer:


  Don't write noisy and obvious comments. The overall rule about code
  commenting is to use them to explain why you solved a problem in a
  given way, or to give any extra information (web links, mathematical
  formulas, etc) that will aid the understanding of a piece of code.
  Explaining what the code is doing should not be necessary if the code is well written. Well written code is self explanatory.




Apart from that, I would also give print_struct_parts() a better name that reflects what kind of struct it is printing. print_time() comes to mind...

Maybe also consider taking a FILE stream as parameter so that the caller is not bound to stdout.