看一下这段代码,它应该以属于结构的三个变量的形式获取用户的出生日期。
printf("Insert date of birth in this format: dd/mm/yyyy\n");
scanf("%d/%d/%d", &user.bDay, &user.bMonth, &user.bYear);
while(isalpha(user.bDay)==1||isalpha(user.bMonth)==1||isalpha(user.bYear)==1){
puts("Invalid input");
scanf("%d/%d/%d", &user.bDay, &user.bMonth, &user.bYear);
}
如果用户输入字符怎么办?像 1q/02/199i 这样的东西?我想让程序打印一条错误消息,并简单地要求用户再次插入他的出生日期。正如您在代码中看到的那样,我尝试使用 isalpha 函数,但它不起作用,程序崩溃并无限次打印“Invalis input”。如何让用户只插入整数?