printf("please input the key: \n") ;
scanf("%d",&p);
while(!(p>=1&&p<=25))
{
printf("Error,please input again:");
getchar();
scanf("%d",&p);
}
其中getchar()语句在这里是什么用的啊 为什么没了他 当输入错误是 会是死循环的啊
还有当输入的p为俩个字母的时候,为什么printf("Error,please input again:");这条语句会执行多遍的啊
各位高手帮帮忙
----------------解决方案--------------------------------------------------------
#include<stdio.h>
int main()
{
int p;
printf("please input the key: \n") ;
scanf("%d",&p);
while(!(p>=1&&p<=25))
{
printf("Error,please input again:");
//getchar();
scanf("%d",&p);
}
return 1;
}
不会啊,可以啊
----------------解决方案--------------------------------------------------------
getchar()读取一个ascii字符 回车也算
----------------解决方案--------------------------------------------------------
怎么上传图片的啊 我传下运行结果
----------------解决方案--------------------------------------------------------
document.body.clientWidth*0.5) {this.resized=true;this.width=document.body.clientWidth*0.5;this.style.cursor='pointer';} else {this.onclick=null}" alt="" />
----------------解决方案--------------------------------------------------------
看下上面的图 当输入2个ww就 运行俩次printf("Error,please input again:"); 3个www就运行了3次
到底怎么回事啊
----------------解决方案--------------------------------------------------------
高手们快来帮我看看啊5555555
----------------解决方案--------------------------------------------------------
有没有完整的代码啊,
当输入2个ww就 运行俩次printf("Error,please input again:"); 3个www就运行了
按你上面的程序,的确是这样啊
----------------解决方案--------------------------------------------------------
完整的代码
#include<stdio.h>
int key(int p) { printf("please input the key: \n") ; scanf("%d",&p); while(!(p>=1&&p<=25)) { printf("Error,please input again:"); getchar(); scanf("%d",&p); }
return p; } char encrypt(int t,int k,char ch[]) { int i; for(i=0;i<t;i++){ if(ch[i]>='a'&&ch[i]<='z') ch[i]=(ch[i]-'a'+k)%26+'A'; if(ch[i]>='A'&&ch[i]<='Z') ch[i]=(ch[i]-'A'+k)%26+'A'; else ; }
} main() { int k,n,i,t=100; char ch[t],s[t]; printf("please input the plaintext: \n"); scanf("%s",ch); n= strlen(ch); t=n; k=key(i); encrypt(t,k, ch); printf("The ciphertext is:\n \t\t\t"); printf("%s\n",ch); }
----------------解决方案--------------------------------------------------------
我就只要运行一次
----------------解决方案--------------------------------------------------------