humanint
2017-03-08 14:46
采纳率: 66.7%
浏览 1.2k
已采纳

c语言中,请问为什么键盘输入数值需要按ctrl+a才会显示结果?

调试,键盘输入数值,需要按ctrl+a才会显示结果,请问这是什么原因呢?
图片说明
#include
#include
#include
#include
#define LEN 30
struct month
{
char name[10];
char abbrev[4];
int days;
int monumbs;
};
struct month months[12]=
{
{ "January","jan",31,1 },
{ "February","feb",28,2 },
{ "March","mar",31,3 },
{ "April","apr",30,4 },
{ "May","may",31,5 },
{ "June","jun",30,6 },
{ "July","jul",31,7 },
{ "August","aug",31,8 },
{ "September","sep",30,9 },
{ "October","otc",31,10 },
{ "November","nov",30,11 },
{ "December","dec",31,12 }
};
int days(int day, char *mon, int year);
int leapyear(int year);
void casing(char *pst);
int main(void)
{
int day, year;
char mon[LEN];
puts("enter the month:");
while (scanf("%s", mon))
{
puts("enter the day and year:");
while (scanf("%d %d", &day, &year) == 2)
if (day > 31 || day < 1)
{
puts("wrong input,again:");
continue;
}
printf("%d %s %d.there are %d days passed by.\n", year, mon, day,days(day, mon, year));
puts("enter the month:");
}
puts("bye!");//hope you won't see this!!
getchar();
return 0;
}

int days(int day, char *mon, int year)
{
int sum,i,pos;
sum = 0;
pos = -1;
casing(mon);
for ( i = 0; i < 12; i++)
{
if (strcmp(months[i].name, mon) == 0)
pos = months[i].monumbs;
}
if (pos >= 0)
{
for (i = 0; i < pos - 1; i++)
sum += months[i].days;
sum = sum + day;
}
else
exit(EXIT_FAILURE);
if (leapyear(year))
return sum++;
else
return sum;
}

int leapyear(int year)
{
if (year % 400 == 0)
return 1;
else if (year % 100 != 0 && year % 4 == 0)
return 1;
else
return 0;
}

void casing(char * pst)
{
if (*pst)
*pst = tolower(*pst);
pst[0] = toupper(pst[0]);///////toupper(pst[0])???
}

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • Black_Will 2017-03-08 15:44
    已采纳

    试一试把while (scanf("%s", mon))和while (scanf("%d %d", &day, &year) == 2)改成while (~scanf("%s", mon))和while (~scanf("%d %d", &day, &year) == 2),就是前面多加一个~

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • Black_Will 2017-03-08 15:49

    你发一下完整的代码,你的代码连头文件都没有。

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题