checking for floating point number
hello guys,
i have a very quick question, which might be very silly, well, i was wondering if there any funtion to find out wheather a eneterd value is a float, int or anything like that. i thought of writting a simple programe to check the value which basically check for an '.' char in a string and at the same time i am not checkking for char 'e' which sometimes used to denote floating num. does any one know any inbuilt function which actully does that.
the code which i wrote
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
char num[20];
int i;
printf("Enter a floating point number\n?");
fgets(num,sizeof(num),stdin);
for(i=0;num[i]!='\0';i++)
{
if(num[i]=='.' && (num[i+1]-'0') >=0)
{
printf("%lf",atof(num));
getchar();
return 0;
}
}
printf("Its not a floating point number");
getchar();
return 0;
}
/*my output
Enter a floating point number
?12.125
12.125000
Enter a floating point number
?1254
Its not a floating point number
*/
thax very much
ssharish2005