Ç - 使用scanf函数(或任何其他功能),以获得INT日期MM / DD / YYYY [英] C - Using scanf (or any other function) to get date MM/DD/YYYY in int
问题描述
我写的类C程序要求我们输入日期的定义为一个结构整数:
typedef结构日期{ INT月;
日整型;
INT年;}日期;
现在,除了它需要真的不会是一个问题,你只能输入它作为MM / DD / YYYY。
我在想,如果我也许可以输入一个字符串,只需使用一个循环来单独三成其他变量的字符串和转换那些为int。
但后来我想起
的printf(请输入日期(MM DD YYYY):);
scanf函数(%D%D,&安培; ...);
是可能的。有没有办法只是'忽略''/'的方式一起?
scanf函数(%D /%D /%D,和D,和放大器;男,&安培; Y );
可能是你在找什么。这将忽略/在输入
I'm writing a C program in class that requires us to input dates as integers in a structure defined as:
typedef struct date{
int month;
int day;
int year;
}Date;
Now that really would not be a problem except it requires that you can only input it as mm/dd/yyyy.
I was thinking if maybe I can input it as a string and just use a loop to seperate the three into other variable strings and convert those to int.
But then I remembered that
printf("Enter Date (MM DD YYYY): ");
scanf("%d %d %d",&...);
is possible. Is there a way to just 'ignore' '/' all together?
scanf("%d/%d/%d",&d,&m,&y);
Is probably what you are looking for. This will ignore the / in the input
这篇关于Ç - 使用scanf函数(或任何其他功能),以获得INT日期MM / DD / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!