c语言其础

来源:百度知道 编辑:UC知道 时间:2024/07/06 21:43:58
1.写出语句scanf("yy-mm-dd=%d-%d-%d",&year,&month,&date);从键盘上的输入形式?
2.上式输入复杂,有没有更好的方法既可以表达输入的提示又可以简化输入量?
第一个问题是不是这样的解决?
#include "stdio.h"
main()
{
int year,month,date;
scanf("yy-mm-dd=%d-%d-%d",&year,&month,&date);
printf("year=%d,month=%d,date=%d",year,month,date);
}

不好意思,打错了不少字。。。现在修改好了
这只能在scanf使用前用printf来提示用户输入了
printf("Input the date like this \"year-month-day\" form");
scanf("%d-%d-%d",&year,&month,&date);
或者是一个一个输入
printf("Input the year:");
scanf("%d",&year);
printf("Input the month:");
scanf("%d",&month);
printf("Input the day:");
scanf("%d",&day);

还有,注意:scanf输入的要原样输入,就是说,下面的,一定要输入xxxx-xx-xx的格式"-"要原样输入,否则会输入错误的,
你的那个是错误的,因为“yy-mm-dd=”要原样输入,并不是原样输出,scanf并没有输出的功能
scanf("yy-mm-dd=%d-%d-%d",&year,&month,&date);