【发布时间】:2017-04-22 07:14:43
【问题描述】:
我被要求在库函数getdate的帮助下编写一个显示系统当前日期的程序,getdate用系统当前日期填充日期结构*datep。 Turbo c++中预定义的日期结构如下所示。
struct date {
int da_year; /*current year */
char da_day; /* day of the month */
char da_mon; /* month (1=Jan) */
};
函数getdate在头文件DOS.H中有如下声明。
void gatdate(struct date *datep);
由于getdate用系统当前日期填充日期结构*datep,我需要制作一个struct date类型的结构变量,调用getdate函数并将变量的地址作为实际参数传递给getdate,然后显示这个结构变量的值应该给我们系统的当前日期。 结构 date 有一个字符变量 da_day 作为它的成员之一来存储系统当前日期的日期。
我的问题是如何存储天数(从 1-28/29/30/31 通常)在字符变量中?
-
另外,按以下方式打印结构变量的值
没有正确给出系统的当前日期。printf("year/day/month is %d/%c/%c",a.da_year,da_day,da_mon); /* a is the structure variable of the type struct date */而下面的陈述给出了正确的日期。
printf("year/day/month is %d/%d/%d",a.da_year,da_day,da_mon);为什么会这样?
【问题讨论】:
-
如果您使用的是 c++,请将其标记为 c++。不是C
-
顺便说一句,在 C++ 中,您更喜欢使用 stream 输出,而不是
printf
标签: c++ function printf structure format-specifiers