所以我需要专门使用struct tm来打印我的生日,我成功了.但是,我还需要使用strftime()以不同的格式打印它.这就是我遇到问题的地方,因为strftime()只识别指针参数.
#include <stdio.h>
#include <time.h>
int main(){
struct tm str_bday;
time_t time_bday;
char buffer[15];
str_bday.tm_year = 1994 - 1900 ;
str_bday.tm_mon = 7 - 1;
str_bday.tm_mday = 30;
str_bday.tm_hour = 12;
str_bday.tm_min = 53;
time_bday = mktime(&str_bday);
if(time_bday == (time_t)-1)
fprintf(stdout,"error\n");
else
{
fprintf(stdout,"My birthday in second is: %ld \n",time_bday);
fprintf(stdout,"My birthday is: %s\n", ctime(&time_bday));//Wed July 22 12:53:00 1998
strftime(buffer,15,"%d/%m/%Y",time_bday);
fprintf(stdout,"My birthday in D/M/Y format is %s",buffer);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误是:
Error: passing argument 4 of ‘strftime’ makes …Run Code Online (Sandbox Code Playgroud)