Skip to main content
Cleaned up the wording.
Source Link
Nocturno
  • 10.1k
  • 5
  • 34
  • 41

As others have stated, there is a single '\n' character in the input stream left over from your earlier call to scanf(). The Standard Library

Fortunately, the standard library function fpurge(FILE *stream) erases any input or output buffered in the given stream. TheWhen placed anywhere between your calls to scanf() and getchar(), the following shouldwill rid stdin of anything left in the buffer:

printf("Do you want to try another number? Say Y(es) or N(o): ");
fpurge(stdin);
response = getchar();

As others have stated, there is a single '\n' character in the input stream left over from your earlier call to scanf(). The Standard Library function fpurge() erases any input or output buffered in the given stream. The following should rid stdin of anything left in the buffer:

printf("Do you want to try another number? Say Y(es) or N(o): ");
fpurge(stdin);
response = getchar();

As others have stated, there is a single '\n' character in the input stream left over from your earlier call to scanf().

Fortunately, the standard library function fpurge(FILE *stream) erases any input or output buffered in the given stream. When placed anywhere between your calls to scanf() and getchar(), the following will rid stdin of anything left in the buffer:

fpurge(stdin);
added 136 characters in body
Source Link
Nocturno
  • 10.1k
  • 5
  • 34
  • 41

As others have stated, there is a single '\n' character in the input stream left over from your earlier call to scanf(). The Standard Library function fpurge() erases any input or output buffered in the given stream. The following should rid stdin of anything left in the buffer:

printf("Do you want to try another number? Say Y(es) or N(o): \n"");
fpurge(stdin);
response = getchar();

The function fpurge() erases any input or output buffered in the given stream. The following should rid stdin of anything left in the buffer:

printf("Do you want to try another number? Say Y(es) or N(o): \n");
fpurge(stdin);
response = getchar();

As others have stated, there is a single '\n' character in the input stream left over from your earlier call to scanf(). The Standard Library function fpurge() erases any input or output buffered in the given stream. The following should rid stdin of anything left in the buffer:

printf("Do you want to try another number? Say Y(es) or N(o): ");
fpurge(stdin);
response = getchar();
Source Link
Nocturno
  • 10.1k
  • 5
  • 34
  • 41

The function fpurge() erases any input or output buffered in the given stream. The following should rid stdin of anything left in the buffer:

printf("Do you want to try another number? Say Y(es) or N(o): \n");
fpurge(stdin);
response = getchar();