I tried printing out the current time on my computer through a character string, by using a pointer. The program works fine, except for one small glitch....it's not printing out the correct time. Instead it's printing out some day in January 2116. I figure it has to be somewhere in the code for the address of the current time.
Here's the code, maybe someone can show me where it went wrong.
Code:
#include <stdio.h>
#include <time.h>
void GetTimeDate (void);
int main()
{
printf("Before the GetTimeDate() function is called.\n");
GetDateTime();
printf("After the GetDateTime() function is called.\n");
return 0;
}
/**********************************The GetDateTime function**************************************/
GetDateTime (void)
{
time_t now;
int i;
char *str;
printf("Within the GetDateTime() function.\n");
time(&now);
str = asctime(localtime(&now));
printf("The current date and time is ");
for (i=0; str[i]; i++)
printf("%c", str[i]);
}
Nymph