char timestamp()
{
time_t ltime;
struct tm * loctime;
char thetime;
time(<ime);
loctime=localtime(<ime);
printf("%s", asctime(loctime));
// "Sat Mar 2 12:12:57 2013"
thetime=*asctime(loctime);
// why "83"?!
return thetime;
}
void WriteLog(char* Msg, ...)
{
FILE logfile;
logfile=*fopen(LOG_FILE, "r+");
fseek(&logfile, 0, SEEK_END);
fprintf(&logfile, "%hhd, %s", timestamp(), Msg);
fclose(&logfile);
}
我觉得这里有一个非常基本的错误。当我打印时间时,它非常好,但是当我尝试将它分配给变量以在另一个函数中使用时,我得到83
的不是实际的日期和时间,当我从 中删除星号时asctime(loctime)
,我得到-128
编译器的警告:Incompatible pointer to integer conversion assigning to 'char' from 'char *'; dereference with *
.