Hi All,
I am working on a code which reads different A2D channels. I need to
have a time stamp for each reading. So, Ideally I want to write a
function that outputs the current time as a string or decimal numbers. I
have the following function based on the examples posted, but it does
not work. Could I get some help on this?
Thanks,
hamid
char *RTClock(void)
{
get the current time from the terminal
struct tm t;
char t_buf[32];
int i;
char *rtcp; pinter to the real time string (int
buffer)
rtcp = &t_buf[0]; put the address in rtcp
printf("Enter current date and time:\n");
printf("YYYY MM DD HH MM SS[enter]\n");
scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
, &t.tm_hour, &t.tm_min, &t.tm_sec);
adjust for tm structure required values
t.tm_year = t.tm_year - 1900;
t.tm_mon = t.tm_mon - 1;
set the time
set_time(mktime(&t));
time_t seconds = time(NULL);
display the time
strftime(t_buf, 32, "%m,%d,%y %I:%M:%S %p\n\r",
localtime(&seconds));
printf(" \n\r Time as a formatted string = %s", t_buf);
printf("Time as a basic string = %s \n\r", ctime(&seconds));
check the pointer
printf(" The pointer to the string is: %p \n\r", &t_buf);
check the time
wait(5);
for (i=0; i < sizeof(t_buf); i++)
{
printf("%c ", *(rtcp + i));
}
pc.printf("\n\r The hour, and minute in time structure was %d:%d
\n", t.tm_hour, t.tm_min);
pc.printf("\n\r
fun.ends
\n\r");
return rtcp;
}
Hi All,
I am working on a code which reads different A2D channels. I need to have a time stamp for each reading. So, Ideally I want to write a function that outputs the current time as a string or decimal numbers. I have the following function based on the examples posted, but it does not work. Could I get some help on this?
Thanks, hamid
char *RTClock(void) {
get the current time from the terminal struct tm t; char t_buf[32]; int i; char *rtcp; pinter to the real time string (int buffer) rtcp = &t_buf[0]; put the address in rtcp printf("Enter current date and time:\n"); printf("YYYY MM DD HH MM SS[enter]\n"); scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday , &t.tm_hour, &t.tm_min, &t.tm_sec);
adjust for tm structure required values t.tm_year = t.tm_year - 1900; t.tm_mon = t.tm_mon - 1;
set the time set_time(mktime(&t)); time_t seconds = time(NULL); display the time strftime(t_buf, 32, "%m,%d,%y %I:%M:%S %p\n\r", localtime(&seconds));
printf(" \n\r Time as a formatted string = %s", t_buf); printf("Time as a basic string = %s \n\r", ctime(&seconds)); check the pointer printf(" The pointer to the string is: %p \n\r", &t_buf); check the time wait(5); for (i=0; i < sizeof(t_buf); i++) { printf("%c ", *(rtcp + i)); } pc.printf("\n\r The hour, and minute in time structure was %d:%d \n", t.tm_hour, t.tm_min); pc.printf("\n\r fun.ends
\n\r"); return rtcp; }