gpt4 book ai didi

CTRL-D 退出程序而不只是循环

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

<分区>

当逐个字符读取输入时,CTRL-D 应激活 EOF 符号并退出循环并在循环后执行 printf 语句。但是,CTRL-D 会完全退出程序。

#include <stdio.h>
#include <ctype.h>

int main() {

int current_character, next_character;

int amount_of_characters = 0, amount_of_words = 0, amount_of_newlines = 0;

while( (current_character = getchar()) != EOF) {

amount_of_characters++;

}

printf("%d", amount_of_characters);

return 0;
}

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