gpt4 book ai didi

c - 如何检查用户是否以正确的格式输入了日期?

转载 作者:行者123 更新时间:2023-11-30 19:44:53 25 4
gpt4 key购买 nike

如何检查用户是否已将日期写入正确的格式 (13/04/1995)

我已经尝试过了

printf("\nPlease enter the patients date of birth in the form (03/04/2013): ");

if (sizeof(scanf("%d/%d/%d", &dob.day, &dob.month, &dob.year)) < 10)
{
printf("Error date needs to be in the format 03/04/2013.");
}
fflush(stdin);

但这只是直接贯穿?

我做错了什么?

最佳答案

如果您使用的是 POSIX 系统(这就足够了),请使用 strptime()解析日期。否则你可以这样做,但请记住返回值是成功转换的数量,而不是字符数。

关于c - 如何检查用户是否以正确的格式输入了日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27188701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com