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 *
.