View Full Version : floating point
03-15-2003, 05:37 PM
I trying to write a program that request users to input a value. If users given the floating point value it would displays "Error!" message. How can C program detect the floating point value from the users.
03-16-2003, 10:15 AM
There isn't a direct way to find the datatype of a variable in C as in some programming languages using a method like typeof. But that is because you specify the datatype when you declare the variable. If you are accepting an input as a character string and trying to figure out whether the user entered an integer, or a character string, or a floating point number, then you could probably check each charater for if it's a number. for example, if all the charaters are numbers then the user entered an integer. If there was a period and/or an "e" in addition to numbers, then the user entered a floating point number; if the input contained any other character then the user entered a character string.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.