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

时间:2013-05-14 10:43:18

标签: c

我在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&lt; input.txt&gt; output.txt


提前致谢!

1 个答案:

答案 0 :(得分:0)

#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;
}
相关问题