我正在编写一个简单的程序来计算用户输入的字符数,我写了一个 if 来检查是否有换行符但仍在打印它..
编码:
#include <stdio.h>
int main()
{
char ch;
int numberOfCharacters = 0;
printf("please enter a word, and ctrl + d to see the resault\n");
while ((ch = getchar()) != EOF)
{
if (numberOfCharacters != '\n')
{
numberOfCharacters++;
}
}
printf("The number of characters is %d", numberOfCharacters);
return 0;
}
我究竟做错了什么?