Originally Posted by
grumpy
Use fgets() to read data from the user as a string of characters. Then check if the content of those characters meet the requirements. Keep doing that until a string is received that meets requirements.
It doesn't necessarily have to be a while loop - any loop construct will do. A do-while loop may be appropriate, as it is will be necessary to read data and check it at least once. For example, you might check for the presence of digits,decimal points, sign ('+' or '-'), and the number of digits after the decimal point. You might also reject input that contains unwanted characters (letters, etc).
Personally, I wouldn't use scanf() for this task at all. And don't make the mistake of trying to use floating point for this.