【发布时间】:2012-08-30 12:41:24
【问题描述】:
我需要按以下格式打印当前日期:今天是星期三 - 2012 年 9 月 7 日。我知道我必须使用该结构
struct tm* time_info;
我可以使用 strftime() 轻松完成此操作,但是,我的任务是不使用 strftime() 并使用 printf 语句直接提取结构的成员。我似乎无法让它正常工作。有什么线索吗?这是我当前的代码:
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <stdlib.h>
/* localtime example */
#include <stdio.h>
#include <time.h>
int main (void)
{
time_t t;
char buffer[40];
struct tm* tm_info;
time(&t);
tm_info = localtime(&t);
strftime(buffer, 40, " Today is %A - %B %e, %Y", tm_info);
puts(buffer);
return 0;
}
代替
strftime(buffer, 40, " Today is %A - %B %e, %Y", tm_info);
我需要
printf("Today is %s, struct members info in the correct format);
【问题讨论】:
-
“我似乎无法让它正常工作”——你试过什么?您发布的代码无关紧要,因为它调用 strftime。另外,由于这是作业,请添加作业标签。