# Thread: QUICK HELP: How to convert what str[i] points at into an integer??

1. ## QUICK HELP: How to convert what str[i] points at into an integer??

Hi!

I have:
char str[100];
int temp;

I use fgets to read in like [2 3 +].
When i = 0, str[i] points at the character 2.
How can I get temp to be 2??

temp = str[i] don't work because str[] is declared as a char.
temp gets another value than 2!
HOw do I convert what str[i] is pointing at into an integer?

2. Simple, just write a little function to do the conversion for you:
Code:
```int ctoi(char c) {
return c - '0';
}

...

temp = ctoi(str[i]);```
Of course, since what you're writing looks like a reverse polish notation calculator, this solution hurts you more than it helps because you can't have numbers with more than one digit without doing something awkward. You'd be better off tokenizing the string and then doing your conversions.

3. ## Re: QUICK HELP: How to convert what str[i] points at into an integer??

Originally posted by valhall
Hi!

I have:
char str[100];
int temp;

I use fgets to read in like [2 3 +].
When i = 0, str[i] points at the character 2.
How can I get temp to be 2??

temp = str[i] don't work because str[] is declared as a char.
temp gets another value than 2!
HOw do I convert what str[i] is pointing at into an integer?