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.
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;
}
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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With