c - Putchar、getchar、while 循环中缺少字符

标签 c while-loop getchar putchar

我对这种和平的代码有疑问,它应该将小写字母更改为大写,并将多个空格变为一个空格。所以它做错了什么,它以某种方式切断了第一个字母,就像当我写“abcdefg”时它给了我输出“BCDEFG”。

main(){ 
int z=0,b;  

        while ( (b = getchar() ) != '\n')
        { 
        b=b-32;
            if (b>0)
            { 
                putchar(b);
            }
            else 
            {
                if (z>=2)
                { 
                    putchar(b);
                }
                else
                { 
                    z=z+1;
                    printf(" ");
                }
            }


        }
}

最佳答案

它似乎为我生成了所有字母...您是否尝试过跟踪它,以找出它在每一步中使用您输入的字符执行的操作?

关于c - Putchar、getchar、while 循环中缺少字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700245/

相关文章:

c++ - 大型3D阵列性能: contiguous 1D storage vs T***

c - 我如何为我的 C 程序计时?

java - JAVA中 "while loop"之后输出不一致

在 c 中的 while 循环中继续接受输入。我试过 fflush

C- getchar() 重新读取字符?

c - 如何修改此函数以使用结构作为参数而不是 double

在链接时定义的 C 常量

c++ - 在 'break' 中使用 'for-loop' 对性能的影响

c - 为什么 getchar() 函数不循环?

c - 如何阅读直到换行