A
A
Andrey Lyubimenko2018-09-28 20:51:54
C++ / C#
Andrey Lyubimenko, 2018-09-28 20:51:54

Why in C does stdin skip user input?

After running this code, everything goes well - until the moment I enter a double number (the last one) - as soon as I start typing, the program ends immediately (not allowing you to enter a number), the transition to the getch () function;

main(){
  int num;
  float x;
  char ch;
  double y;
    printf("\n\tEnter int:");
      scanf("%d", &num);
    printf("\n\tEnter float:");
      scanf("%f", &x);
    printf("\n\tEnter char:");
      scanf("%ñ", &ch);
    printf("\n\tEnter double:");
      scanf("%lf", &y);
  getch();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-09-28
@andrewlybimenko

scanf("%ñ", &ch);

Tell me, what kind of format is this ?
scanf cannot interpret it and therefore does not inject anything with this scanf. And introduces the next.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question