getchar() 和 printf 执行时出现问题

问题描述 投票:0回答:1

我目前正在学习“C 编程语言”。但是,我被困在 getchar() 部分。

我附加的代码与教科书匹配,应该计算输入中存在的字符。

#include "stdio.h"

void countChar(){

    long nc = 0;

    while (getchar() != EOF)
        ++nc;
    printf("%ld\n", nc);

运行代码并输入内容后,不会返回任何字符数。这是 printf 的问题还是我的代码中的其他问题?

任何帮助将不胜感激。

Here is the result of running the code

c printf clion getchar
1个回答
0
投票
#include "stdio.h"

应该是

#include <stdio.h>
© www.soinside.com 2019 - 2024. All rights reserved.