gpt4 book ai didi

C printf() 不返回值

转载 作者:太空宇宙 更新时间:2023-11-04 00:11:13 25 4
gpt4 key购买 nike

我有一个非常简单的 C 示例程序,它对输入的字符、单词和空格进行粗略计数。该程序编译没有错误,但在测试时该程序不会通过 print 函数返回任何 int 变量。我正在使用 VS2012 进行编码和编译。单步执行代码表明正在正确计算这些值。我的代码或编译器有问题吗?

#include <stdio.h>

#define IN 1
#define OUT 0
/* count digits, white space, others */
main()
{
int c, nl, nw, nc, state;

state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF){
++nc;

if(c == '\n'){
++nl;
}

if (c == ' ' || c == '\n' || c == '\t'){
state = OUT;
} else if (state == OUT){
state = IN;
++nw;
}

}

printf("%d %d %d\n", nl, nw, nc);
}

最佳答案

如果您使用 stdin 运行它,它会起作用来自文件 a.exe < test.txt .如果您使用 stdin 运行它,它会起作用来自 Linux 上的控制台。如果您使用 stdin 运行它,它将不起作用来自 Windows 上的控制台。

这一定是某种 Windows 控制台异常。

关于C printf() 不返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29307586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com