firstly i have tried typecasting a string to an integer or rather an element of an array which is a string e.g.
-
string[0] = "2";
-
int a = (int)string[0];
-
and i know that for c++ you can use atoi which works fine;
But i need the conversion to work on c, atoi doesn't seem to be working and when i try the typecast conversion it goes from the number 2 to some like 23465???
Any help is greatly appreciated this completely seperate from any other of my posts just to clarify.
Well ofcourse atoi doesn't work when you are trying to call it with string[0] as a parameter.Atoi takes a const char *ptr,adn you are giving him a single char.
Conversion from char to int is automatic so if you say
a=string[0];
and string[0]='2'(which is ASCII value of 50(usually) or '0'+2),a will become 50 or '0'+2.But you need it to be 2,right?
So what are you going to do?
There is a way to do it with atoi,but it's rather cumbersome.It's better to stick with this one.