文号
t56257
阅读
4644
回复
9
收藏
4
学c语言遇见问题(小问题)
2013/04/21
IP:福建
将输入的字符中大写改为小写并加密,这个程序中,为什么去掉第6那一行就正常运行,加上后,输入p按回车直接得出(1111111Press any key to continue)
#include<stdio.h>
#include<ctype.h>
main()
{
char c;
while(getchar()!='p'); //为什么这一行去掉就正常
printf("1111111");
c=getchar();
while(c!='\n')
{
if(isalpha(c))
{
c=tolower(c);
c=(c-'a'+1)%26+'a';
}
putchar(c);
c=getchar();

}

}
13年8个月前IP:未同步
518412
2楼
回 1楼(celeron533) 的帖子
例如,语句while(getchar()!='p');printf("aabbcc");这个语句意思是,当s输入p按enter键时,程序才往下继续执行下一语句.所以我那个并没错。
引用
评论
13年8个月前IP:未同步
518415
3楼
回 1楼(celeron533) 的帖子
您是说,输入p按回车,这个回车会被第二个c=getcgar()中的getchar()吃掉?
引用
评论
13年8个月前IP:未同步
518435
6楼
回 4楼(celeron533) 的帖子
啊,恍然大悟,当我输入pabcd按回车时,程序将abcd正确加密为bcde,而且做了个实验,果然后来的getchar会吃掉回车;
#include<stdio.h>
void main()
{
    char a,b;
    int e=1;
    a=getchar();
    if(e<2){
    b=getchar();
    putchar(b);
    putchar(b);}
}                                                                     实验步骤:输入z按回车
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的