1

I have a simple piece of code that will echo whatever you type into the console:

int main(){
    setvbuf(stdout, NULL, _IONBF, 0);
    char c = -1;
    while(scanf("%c", &c) == 1){
        printf("%c", c);
    }
}

But when I Debug this code in Eclipse CDT it outputs the following without me typing anything into the console.

47-thread-select 1

How can I disable this from being fed into the input stream? Also sometimes if I run this there are multiple lines being outputted so I cannot simply discard 1 line.

Verv
  • 2,181
  • 2
  • 17
  • 32
ModDL
  • 360
  • 2
  • 13
  • Required reading: [C FAQ - `scanf`](http://c-faq.com/stdio/scanfprobs.html) – Thomas Matthews Aug 23 '17 at 20:37
  • Does this happen when you run or debug your code outside of Eclipse CDT? Do you know where that output is coming from? – HighCommander4 Aug 24 '17 at 04:02
  • This problem does not occur in Visual Studio for Run or Debug. This only occurs when launching the program using the "Debug " option in Eclipse CDT and does not occur using the "Run " option. – ModDL Aug 24 '17 at 04:13
  • Under further examination I found that the standard input stream was fighting with the GDB console. The inputs given via a file was causing errors in the GDB console whilst commands in the GDB console is being picked up by scanf. – ModDL Aug 24 '17 at 04:25
  • What method do you use to get the program to read from a file while debugging in CDT? Also, which versions of both GDB and CDT are you using? – simark Aug 31 '17 at 19:04

0 Answers0