0

Eclipse 21-09 (Ubuntu) + CDT 10,4 GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2 gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

I Created a c/C++ project → C Managed Build → Executable (empty) (toolchain Linux Gcc) Created a small snipped of C code for scanf; Build and selected to debug

WHAT happen, is that -the debugger step into lines, when it arrives to the scanf the debug cursor disappear,.. seems to wait for an input.. -BUT if I move to de consolle tab, and enter some numbers and press nothing happens… -I’ve got to digit a second line and 2nd (?!?!) than the program seems to wake up.. If a set a scanf with multiple items, the things get even worst...

-WHAT can cause the problem in the Eclipse console?

-Which information/file can I give you to understand what’s preventing the scanf to return ?

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char op;
    int n1 = 0;
    int n2 = 0;
    int control;

    
    control = scanf(" %d ", &n2);
    printf("you enter %d\n", n2);
/*  
    control = scanf(" %c %d %d ", &op, &n1, &n2);
    printf("You entered: char %c, num1 %d, num2 %d", op, n1, n2);
    */

}
Giuliano69
  • 11
  • 4
  • Please remove the trailing space so that `scanf(" %d ", &n2)` is `scanf(" %d", &n2)`. Please see [What is the effect of trailing white space in a scanf() format string?](https://stackoverflow.com/questions/19499060/what-is-the-effect-of-trailing-white-space-in-a-scanf-format-string) Every detail of the `scanf` format string is meaningful. – Weather Vane Feb 07 '22 at 18:04
  • 1
    It works now !!Thanks Vane for your help. You updated my (poor) knowledge of scan format string.... Thanks also for your link ! – Giuliano69 Feb 07 '22 at 18:43
  • It's quite a tricky function, and the format specifiers don't all behave the same way. – Weather Vane Feb 07 '22 at 19:12

0 Answers0