I appreciate Your help very much, however again it doesn't work properly. At least now, there's no segmentation fault
isdigit seems to be not detecting numbers, and even though I clear the buffer, there is no possiblity to enter char d, to decide if we want to finish the loop.
Code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int main()
{
int i, j, found, yes;
char d;
char input[20];
do {
printf("Please enter a number\n");
scanf("%s", input);
j = 0;
for (i = 0; i < 20; i++) {
if (isdigit(input[i]) == 1) {
j++;
}
}
if(j == strlen(input))
yes = 1;
if (yes == 1)
found = 1;
else
found = 0;
if (found == 1)
printf("Thanks for the number");
else {
printf("It is not a number. Please enter a number");
printf("Press r to repeat\n");
}
fflush(stdin);
scanf("%c", &d);
} while (d != 'r');
return 0;
}
Thanks in advance!