c - 用 C 编写代码时使用 '\n'

标签 c

我是 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/

相关文章:

c - 当在c中输入空行时如何使此代码中的循环停止

c - struct-C 中字符串的二维数组

c - C 中数组类型有不完整元素类型错误

c - 抛出异常: Access violation writing location 0x00000000

c++ - 如何在两个无限循环之间交替?

c - 如果 sftp 无法将文件放入 sftp 服务器,如何获取并处理 C 程序中的返回代码?

c++ - 结构前缀的布局

c - 如何为 C11 U“unicode 文字”正确使用 `__attribute__((format (printf, x, y)))`?

c++ - clang: error: linker command failed with exit code 1 (使用 -v 查看调用) MINIX3

C - 使用指向函数的指针没有结果