Tyoecasting Char[] to Int

Hi, how do I convert a character array to a numerical value for use in operations? Or the other way around? Typecasting like with
1
2
char my_var[256] = "52";
(int) my_var;


Doesn't seem to be working. It's giving me ASCII codes, I think.

Thanks and good day,
YottaFlop.
If I'm understanding you correctly, you're going to want to look at int atoi (const char* str).

Usage:

1
2
char my_var_char[256] = "52";
int my_var_int = atoi(my_var_char);


Don't forget to consider the possibility that an overflow might occur. In other words, if the string representation of the number is too big to fit in an int variable, you might not get what you expect.
Ah, facepalm! I can't believe I forgot about that! Thanks. :)
Topic archived. No new replies allowed.