C语言没有输入直接输出问号
#include<stdio.h>#include<string.h>intmain(){intn,i,j;chara[7],b[7],c[7];charge[14][5...
#include <stdio.h>
#include<string.h>
int main()
{
int n,i,j;
char a[7],b[7],c[7];
char ge[14][5]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char shi[12][4]={"tam","hel","maa","huh","tou", "kes","hei","elo","syy","lok","mer","jou"};
scanf("%d",&n);
for(i=0;i<=n;i++){
gets(a);
b[2]=a[2];
printf("%c\n",b[2]);
int w=a[0]-'0';
int len=strlen(a);
if(w>=0&&w<=9){int g,s;
if(len==1){printf("%s\n",ge[w]);continue;}
if(len==2){
int q=w*10+(a[1]-'0');g=q%13;s=q/13;
if(g==0){printf("%s\n",shi[s-1]);}
else{printf("%s %s\n",shi[s-1],ge[g]);}continue;}
if(len==3){
int q=100+(a[1]-'0')*10+(a[2]-'0');g=q%13;s=q/13;
if(g==0){printf("%s\n",shi[s-1]);}
else{printf("%s %s\n",shi[s-1],ge[g]);}continue;}
}
if(w>10){
if(len<=5)
{for(j=0;j<14;j++)
{if(strcmp(a,ge[j])==0)
{printf("%d\n",j);break;}
if(strcmp(a,shi[j])==0)
{printf("%d\n",(j+1)*13);break;}
}
}
if(len>5){int o,p;
for(j=0;j<14;j++)
{if(strcmp(b,shi[j])==0){o=13*(j+1);break;}}
for(j=0;j<14;j++)
{if(strcmp(c,ge[j])==0){p=j;break;}}
printf("%d\n",p+o);}
}
}
return 0;
}
然后运行的时候先输入n=5,然后还没等输入a的字符串 他直接给我输出一个问号。这个怎么搞? 展开
#include<string.h>
int main()
{
int n,i,j;
char a[7],b[7],c[7];
char ge[14][5]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
char shi[12][4]={"tam","hel","maa","huh","tou", "kes","hei","elo","syy","lok","mer","jou"};
scanf("%d",&n);
for(i=0;i<=n;i++){
gets(a);
b[2]=a[2];
printf("%c\n",b[2]);
int w=a[0]-'0';
int len=strlen(a);
if(w>=0&&w<=9){int g,s;
if(len==1){printf("%s\n",ge[w]);continue;}
if(len==2){
int q=w*10+(a[1]-'0');g=q%13;s=q/13;
if(g==0){printf("%s\n",shi[s-1]);}
else{printf("%s %s\n",shi[s-1],ge[g]);}continue;}
if(len==3){
int q=100+(a[1]-'0')*10+(a[2]-'0');g=q%13;s=q/13;
if(g==0){printf("%s\n",shi[s-1]);}
else{printf("%s %s\n",shi[s-1],ge[g]);}continue;}
}
if(w>10){
if(len<=5)
{for(j=0;j<14;j++)
{if(strcmp(a,ge[j])==0)
{printf("%d\n",j);break;}
if(strcmp(a,shi[j])==0)
{printf("%d\n",(j+1)*13);break;}
}
}
if(len>5){int o,p;
for(j=0;j<14;j++)
{if(strcmp(b,shi[j])==0){o=13*(j+1);break;}}
for(j=0;j<14;j++)
{if(strcmp(c,ge[j])==0){p=j;break;}}
printf("%d\n",p+o);}
}
}
return 0;
}
然后运行的时候先输入n=5,然后还没等输入a的字符串 他直接给我输出一个问号。这个怎么搞? 展开
1个回答
2017-08-05
展开全部
因为输入的回车和换行的问题,导致随后的那个for循环结束了,这行 printf("%c\n",b[2]); 就输出了未确定的值
~
~
~
~
~
~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询