C语言解决scanf输入空值不继续的问题

解决问题

我的解决办法是自己实现输入功能

#include <stdio.h>
int main(int argc, char const *argv[])
{
    while (1)
    {
        printf("command > ");
        char command[256];
        int i = 0;
        while (1)
        {
            char buf = getchar();
            if (buf == '\n')
            {
                i = 0;
                break;
            }else
            {
                command[i] = buf;
                i++;
            }
        }
        if (command[0] != '\0')
        {
            printf("%s\n", command);
            command[0] = '\0';
        }
    }
    return 0;
}

标签: none

添加新评论