小编Nat*_*ing的帖子

在 C 中输入日期作为字符,无法解决如何避免 /

#include <stdio.h>

int main(void)
{
    char day[3] = {""};
    char month[3] = {""};
    char year[5] = {""};

    printf("Date of Birth: ");
    scanf("%s[^/]%*c%s[^/]%*c%s", &day, &month, &year);
    printf("\n1. %s", day);
    printf("\n2. %s", month);
    printf("\n3. %s", year);
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试输入日期并丢弃/. 目前,整个条目存储在 char day[3] 中,其他三个字符留空。

我使用 char 是因为我想保留前导零,并且我使用字符串来创建没有/.

c date scanf

2
推荐指数
1
解决办法
54
查看次数

标签 统计

c ×1

date ×1

scanf ×1