itoa()

This is a discussion on itoa() within the C++ Programming forums, part of the General Programming Boards category; I'm trying to count how many times a number appears in an array. Basically you have something like this: Code: ...

1. itoa()

I'm trying to count how many times a number appears in an array. Basically you have something like this:

Code:
```int array[3][3] ={	{'23', '31', '2349'},
{'7567', '1', '84'},
{'355', '75', '12 '}};
int three = 0;
int five = 0;```
Now I need to count how many times a number appears in that array. I.e. 355 would make three = 1 and five = 2. So I need to break down these numbers into chars or something where I can count each one. Can anyone tell me how to do this?

2. You could read the FAQ on Convert an int to a string (C++).

I note that single quotes are used to delimit chars, so you should probably drop them from your example code.

3. Edit: I think I misread the problem. The values are already ints, you want to convert to string to make it easier. That makes more sense than what I was originally thinking you were trying to do (the quotes threw me off).

An alternate solution to converting to a string would be to use division and modulus with multiples of 10 to find the separate digits of each number.

4. If I was doing this, I'll just loop in the array...

5. when you mod a decimal number by 10 you get the digit in the 0's place.
when you divide it you truncate the number, given you divide it into an int and not a float.