gpt4 book ai didi

c - 使用输入重定向暂停 C 程序

转载 作者:行者123 更新时间:2023-11-30 17:51:45 24 4
gpt4 key购买 nike

我用 c 语言编写了以下简单代码,并通过批处理文件使用了输入重定向。如何在 while 循环中暂停程序?

#include <stdio.h>

int main(void)
{
char buffer[2048];

while ( !feof(stdin) ) {
gets( buffer );
printf( "%s", buffer );
//I want to pause the program here, until i press enter
}
return 0;
}

批处理文件是:main.exe < 输入.txt > 输出.txt

<小时/>

提前致谢!

最佳答案

#include <stdio.h>
#include <conio.h>

int main(void){
char buffer[2048];

while ( !feof(stdin) ) {
gets( buffer );
printf("%s", buffer );
while(!_kbhit());
_putch('\n');
while(_kbhit())
_getch();
}
return 0;
}

关于c - 使用输入重定向暂停 C 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16541103/

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