R
RVO
Hi,
I am having a problem understanding why this code works.
As I understand it the "ctime" function returns a string. In main the
returned "string" is assigned to an integer (16 bit) and is printed with
a string format in MAIN.
Would someone kindly explain how this works and/or correct my understanding?
#include <stdio.h>
#include <time.h>
// Gets System Date and Time
int main(void)
{
int i;
i = mytim();
printf("D/T= %s", i);
}
mytim()
{
time_t now;
if( (now = time(NULL)) == (time_t) - 1 )
puts("FAIL: Unable to get time");
else
printf("Date & time: %s", ctime(&now));
// Either of following works equally well
return (ctime(&now));
}
I am having a problem understanding why this code works.
As I understand it the "ctime" function returns a string. In main the
returned "string" is assigned to an integer (16 bit) and is printed with
a string format in MAIN.
Would someone kindly explain how this works and/or correct my understanding?
#include <stdio.h>
#include <time.h>
// Gets System Date and Time
int main(void)
{
int i;
i = mytim();
printf("D/T= %s", i);
}
mytim()
{
time_t now;
if( (now = time(NULL)) == (time_t) - 1 )
puts("FAIL: Unable to get time");
else
printf("Date & time: %s", ctime(&now));
// Either of following works equally well
return (ctime(&now));
}