A Little C Primer/C Standard Utility Library & Time Library

The utility functions library features a grab-bag of functions. It requires the declaration: #include &lt;stdlib.h&gt;

Useful functions include: atof( &lt;string&gt; )    Convert numeric string to double value. atoi( &lt;string&gt; )    Convert numeric string to int value. atol( &lt;string&gt; )    Convert numeric string to long value. rand              Generates pseudorandom integer. srand( &lt;seed&gt; )     Seed random-number generator -- "seed" is an "int". exit( &lt;status&gt; )    Exits program -- "status" is an "int". system( &lt;string&gt; )  Tells system to execute program given by "string". abs( n )            Absolute value of "int" argument. labs( n )           Absolute value of long-int argument.

The functions "atof", "atoi", and "atol" will return 0 if they can't convert the string given them into a value.

The time and date library includes a wide variety of functions, some of them obscure and nonstandard. This library requires the declaration: #include &lt;time.h&gt;

The most essential function is "time", which returns the number of seconds since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds. It returns a value as "time_t" (a "long") as defined in the header file.

The following function uses "time" to implement a program delay with resolution in seconds: /* delay.c */

#include &lt;stdio.h&gt;

#include &lt;time.h&gt;

void sleep( time_t delay );

void main {    puts( "Delaying for 3 seconds." ); sleep( 3 ); puts( "Done!" ); }

void sleep( time_t delay ) {    time_t t0, t1; time( &amp;t0 ); do    { time( &amp;t1 ); }    while (( t1 - t0 ) &lt; delay ); }

The "ctime" function converts the time value returned by "time" into a time-and-date string. The following little program prints the current time and date: /* time.c */

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

void main {    time_t *t; time( t ); puts( ctime( t ) ); } This program prints a string of the form: Tue Dec 27 15:18:16 1994