I am scanning a string and I want that string to be only integer type elements so I did some validation for it and it worked for characters but it isn't working good enough for floating points. For e.g. If I enter 1.2 value as input then it does not desired output for single digit and works for 2 digit and more. Similarly if I enter 12.3 then it does not desired output for two digit and works for 3 digit and more. Can anyone tell me what's going on in here? Is there any way I can delete all the elements entered in the string so that I can get only integer values?
P.S. I am using string because I need to take number input from string as per my given question of program.
printf("Enter the number you want to convert into words:\n\n-->");
gets(numberToBeConvertedToWords);
for (i = 0; i != strlen(numberToBeConvertedToWords); i++)
{
while (isdigit(numberToBeConvertedToWords[i]) == 0)
{
// deleting the characters entered in the string.
memset(numberToBeConverted, 0, sizeof(numberToBeConverted));
printf("Please enter positive integers only.\n\n-->");
gets(numberToBeConvertedToWords);
}
}
printf("Entered number: %d", numberToBeConvertedToWords);
convertAndPrintNumberToWords(numberToBeConvertedToWords);