我正在尝试调试使用Eclipse用C ++编写的程序。 该程序包括从用户那里获取输入,但是当我将输入输入到控制台时,它将永远不会继续运行代码(它将继续要求输入)。 如果不解决此问题,我将无法调试,希望对您有所帮助。 谢谢。
I'm trying to debug a program I wrote in C++ using Eclipse. The program includes getting input from the user but when I enter the input to the console it won't ever continue running the code (it'll keep asking for input). I can't debug without fixing this and would appreciate some help. Thank you.
代码被困在while循环fgets中:
The code gets stuck on the while loop fgets:
int main(int argc, const char**argv) { FILE* inputFile = NULL; setlocale(LC_ALL, ""); if(argc == 2){ inputFile = fopen(argv[1], "r"); if (inputFile == NULL){ printf("Problem opening file %s, make sure correct path name is given.\n", argv[1]); return 0; } } else { inputFile = stdin; } char buffer[MAX_STRING_INPUT_SIZE]; // Reading commands while ( fgets(buffer, MAX_STRING_INPUT_SIZE, inputFile) != NULL ) { fflush(stdout); if ( parser(buffer) == error ){ printf("ERROR\n"); break; } }; fclose(inputFile); return 0; }推荐答案
问题来自Eclipse缓冲控制台输入。 修复它的一种方法是强制Eclipse使用Windows / DOS本机控制台进行调试。
The issue comes from Eclipse buffering the console inputs. One way to fix it is to force Eclipse to debug using a Windows/DOS native console.
详细说明了该过程,但要简短地说:
The procedure is described in details here, but in brief :
更多推荐
使用控制台输入进行Eclipse调试
发布评论