Richard van den Berg schrieb in Nachricht ...
Quote:
>> Has anyone used the function ctime() in one of their programs? Could you
>> please tell me how you used it? I don't quite understand how ctime()
works
>> when called in a program...
>Simply said you have to allocate a structure and call ctime() with the
>pointer to the structure and then ctime() returns the time values in the
>structure.
>> I'm to write a function that takes in a time specified by the user (e.g.
>> 12:00), output the current time (using ctime() <--???), and block for
the
>> number of seconds difference between the two.
>It's explained in appendix B in K&R 2nd edition, I can provide you an
>example program that uses localtime() and returns the dutch value of the
>current date, either independant or as a module.
>> Is there a better time function that I can use other than ctime() ?
>As I understand ctime() conforms K&R C I guess it wil be ANSI too.
>Regards,
>Richard
>--
Which date function you use depends on what you wnat to do whit date info. I
prefer localtime(), because I'm free in collecting an formatting the date.
If you don't like pointers, try this, it should clearly demonstrate the use
of ctime():
<code>
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t t;
time(&t);
printf("Today's date and time: %s\n", ctime(&t));
return 0;
}
<end code>
Regards
G.Pohl
--