J
jconnort
I'm trying to write a function to get the current system time, so I can
use it when I need to output it to a log, below is the code I'm
testing:
#include "include.h"
#include <stdlib.h>
main(argc, argv)
int argc;
char **argv;
{
int GetCurrentTime();
struct tm *time_struct;
GetCurrentTime(time_struct);
fprintf(stdout, "Starting get_error_checks run on: %d...\n\n",
time_struct->tm_year+1900);
exit(0);
}
int GetCurrentTime(ts_ptr)
struct tm *ts_ptr;
{
static char *weekday[7] = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
static char *month[12] = {"January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November", "December"};
time_t time_value=0;
/* Retrieve current time information from the Operating System . . .
*/
time(&time_value);
ts_ptr = localtime(&time_value);
fprintf(stdout, "**\tGetCurrentTime %s, %s %d, %d
%d:%02d\n**\n**\n*/\n\n\n",
weekday[ts_ptr->tm_wday],
month[ts_ptr->tm_mon],
ts_ptr->tm_mday,
ts_ptr->tm_year+1900,
ts_ptr->tm_hour,
ts_ptr->tm_min);
return;
}
The "include.h" just has stdio.h, time.h and sys/systypes.h as further
includes. This seems to work fine in the function call but I can't get
the caller to "know" about the changes. I've tried declaring
time_struct as just a pointer (as above) or having a struct declared,
passing in time_struct, &time_struct (which I think are the same in
this case ?) having a separate pointer to the struct get passed, with
no luck. Obviously I'm missing something fundamental here, can anyone
help ? I have been going through FAQs and some some similar issues...
use it when I need to output it to a log, below is the code I'm
testing:
#include "include.h"
#include <stdlib.h>
main(argc, argv)
int argc;
char **argv;
{
int GetCurrentTime();
struct tm *time_struct;
GetCurrentTime(time_struct);
fprintf(stdout, "Starting get_error_checks run on: %d...\n\n",
time_struct->tm_year+1900);
exit(0);
}
int GetCurrentTime(ts_ptr)
struct tm *ts_ptr;
{
static char *weekday[7] = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
static char *month[12] = {"January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November", "December"};
time_t time_value=0;
/* Retrieve current time information from the Operating System . . .
*/
time(&time_value);
ts_ptr = localtime(&time_value);
fprintf(stdout, "**\tGetCurrentTime %s, %s %d, %d
%d:%02d\n**\n**\n*/\n\n\n",
weekday[ts_ptr->tm_wday],
month[ts_ptr->tm_mon],
ts_ptr->tm_mday,
ts_ptr->tm_year+1900,
ts_ptr->tm_hour,
ts_ptr->tm_min);
return;
}
The "include.h" just has stdio.h, time.h and sys/systypes.h as further
includes. This seems to work fine in the function call but I can't get
the caller to "know" about the changes. I've tried declaring
time_struct as just a pointer (as above) or having a struct declared,
passing in time_struct, &time_struct (which I think are the same in
this case ?) having a separate pointer to the struct get passed, with
no luck. Obviously I'm missing something fundamental here, can anyone
help ? I have been going through FAQs and some some similar issues...