#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdlib.h>
void main()
{
char a[99];
float b;
cin>>a;
if(!isalpha(a[0]))
{
b=atof(a[0]);
}
b+=10;
cout<<b;
getch();
}
// above program doesn't result in desired way... help me to debug.... i'm using 'turbo c++ 3.0'
actually it's bigger program.... but I simplified to review the specific problem with 'atof' function.
as you know the above program doesn't has real world application..
in this program i tried to get a string value as input and check the value is not an alphabetic letter.
then the string value will be converted into float value. And the float value+10 should be my output . But the program not even compile. it shows two errors and they are...
(1.)can't convert to 'int' to constant 'char *'
(2.)Type mismatch in parameter '__s' in call to 'atof(constant char *)'
Alphabetic letters aren't generally illegal in floating point number expressions - eg. 1.005e+20 is a legal expression. And just because a character is no alphabetic letter doesn't guarantee it's a number.
PS: You are using ancient C++ here. It's int main, not void main (since a very long time too) - same for iostream.h and stdlib.h and ctype.h (instead of iostream, cstdlib and cctype). atof takens an entire string, not just a single character like you do.
thank you filipe... yes isalpha takes a character and atof takes whole string.....
again thanks filipe...
after this change float value too compile instead of double...
what it's actual return type?? why both got compiled?