A simple query
Is there any way to know the system date automatically using a c program ?
If yes please guide me through some codes !!
harshchandra
Junior Poster in Training
68 posts since Nov 2004
Reputation Points: 7
Solved Threads: 1
There functions in such as time, localtime, and strftime.
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t now;
if ( time(&now) != (time_t)(-1) )
{
struct tm *mytime = localtime(&now);
if ( mytime )
{
char buffer [ 32 ];
if ( strftime(buffer, sizeof buffer, "%x", mytime) )
{
printf("buffer = \"%s\"\n", buffer);
}
}
}
return 0;
}
/* my output
buffer = "06/08/05"
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314