getting infinite loop in c while using eof for specific value of input

shri_wahal

The following code in C accepts integers as long as data is fed into it.

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
while(scanf("%d",&x)!=EOF)
{
  printf("%d\n",x);
}
getche ();
}                                                     

It works fine for integer inputs but on entering any character/float input it becomes an infinite loop.Why is it so ?

Some programmer dude

If scanf failes to parse any input, it will leave the input in the buffer and return 0. As the erroneous input will never leave the buffer and you don't check for anything but EOF being returned, the loop will continue for ever.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Program entering in a infinite loop only with a specific value

From Java

'while' infinite loop using scanner input and pos/neg numbers

From Java

Java infinite while loop, specific program question

From Java

Infinite loop while using Matcher in Java

From Dev

do-while infinite loop with if c++

From Dev

Infinite loop while using ?: condition inside "for" loop

From Dev

freeing memory in a while loop keeps getting stuck an infinite loop

From Dev

Stuck in infinite loop while traversing an array in C

From Dev

Getting infinite loop instead of a value

From Dev

Infinite Loop while using react hook

From Dev

Infinite while loop with a std::ofstream C++

From Dev

Python - Infinite while loop, break on user input

From Dev

while loop infinite validation response to incorrect input

From Dev

Getting Infinite loop while using string.size()

From Dev

infinite while loop using bufferedreader

From Dev

Stopping an infinite while loop using scanf in c?

From Dev

Infinite loop while converting pseudocode to C++

From Dev

Getting user input in a while loop

From Dev

Infinite while loop in C when given value and subtracting until zero

From Dev

C: Parsing a file with fgetc() - EOF infinite loop

From Dev

Getting specific value with a checkbox input using on click

From Dev

While loop that ends when using EOF in inner while loop

From Dev

Getting the minimum value from user input in a while loop

From Dev

Unable to do sum and getting same value by using while loop php

From Dev

I keep getting an infinite loop in c++

From Dev

infinite while loop while using fscanf

From Dev

while I'm getting infinite while loop in java

From Dev

How to end a infinite while loop with user input

From Dev

Getting infinite loop in C++ while-loop, why is this happening?

Related Related

  1. 1

    Program entering in a infinite loop only with a specific value

  2. 2

    'while' infinite loop using scanner input and pos/neg numbers

  3. 3

    Java infinite while loop, specific program question

  4. 4

    Infinite loop while using Matcher in Java

  5. 5

    do-while infinite loop with if c++

  6. 6

    Infinite loop while using ?: condition inside "for" loop

  7. 7

    freeing memory in a while loop keeps getting stuck an infinite loop

  8. 8

    Stuck in infinite loop while traversing an array in C

  9. 9

    Getting infinite loop instead of a value

  10. 10

    Infinite Loop while using react hook

  11. 11

    Infinite while loop with a std::ofstream C++

  12. 12

    Python - Infinite while loop, break on user input

  13. 13

    while loop infinite validation response to incorrect input

  14. 14

    Getting Infinite loop while using string.size()

  15. 15

    infinite while loop using bufferedreader

  16. 16

    Stopping an infinite while loop using scanf in c?

  17. 17

    Infinite loop while converting pseudocode to C++

  18. 18

    Getting user input in a while loop

  19. 19

    Infinite while loop in C when given value and subtracting until zero

  20. 20

    C: Parsing a file with fgetc() - EOF infinite loop

  21. 21

    Getting specific value with a checkbox input using on click

  22. 22

    While loop that ends when using EOF in inner while loop

  23. 23

    Getting the minimum value from user input in a while loop

  24. 24

    Unable to do sum and getting same value by using while loop php

  25. 25

    I keep getting an infinite loop in c++

  26. 26

    infinite while loop while using fscanf

  27. 27

    while I'm getting infinite while loop in java

  28. 28

    How to end a infinite while loop with user input

  29. 29

    Getting infinite loop in C++ while-loop, why is this happening?

HotTag

Archive