我是 C 初学者,我写了这段代码。我想知道为什么这不适用于 '\n' 但它仍然适用于 '\t'。有人可以帮帮我吗?谢谢。
int count=0;
while(1)
{
key[count]=getch();
if(key[count]=='\n') //The condition works well when a '\t' is used instead
{
break;
}
else
{
printf("*");
}
count++;
}
最佳答案
I would say it depends on the operating system.
请注意,当您按 Enter 时,您会按“\r\n”而不仅仅是“\n”。
尝试使用文件中的输入运行代码,我打赌它会起作用。
此外,如果您对 \n
感兴趣,请查看此 question也是。
关于c - 用 C 编写代码时使用 '\n',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22883980/