c - 我如何只让用户在 c 中输入一个字符

标签 c loops input fgets gets

如果我只希望用户输入一个字符,我将如何用 C 语言来实现。我对此的尝试如下,但失败得很惨。根据我在网上阅读的内容,我听说您可以使用函数 gets 或 fgets 来完成此操作,但我不知道如何操作。

do
{
    geussNumber += 1;
    printf("Enter guess number %d\n", geussNumber);
    scanf(" %c", &geussLetter);
    scanf ("%c", &inputViolation);
        if (isalpha(geussLetter) == 0)
        {
            printf("You did not enter a letter\n");
        }
        else if (inputViolation == true)
        {
            printf("You eneterd more than one letter\n");
        }
        else
        {
        inputLoopEnd = 1;
        }
}
while( inputLoopEnd == false );

最佳答案

您可以使用 getc 系列函数。

看看http://quiz.geeksforgeeks.org/difference-getchar-getch-getc-getche/例如。

关于c - 我如何只让用户在 c 中输入一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38440680/

相关文章:

java - 如何使用循环验证选择菜单

C/C++ : Why is it impossible to declare a pointer in loop initialization

Powershell 检查日志文件,如果发现错误代码则重新启动服务

带有文本和按钮的 Java 对话框

java - 使用 getText 获取整数

Windows下编译Mongoose的hello.c

c - 如何在linux内核中重用变量?

c++ - IDCT矩阵的无分支生成?

c拼图(if语句)

c++ - 来自 C++ 控制台的大量输入