# itoa()

• 06-26-2007
vikernes
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?
• 06-26-2007
laserlight
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.
• 06-26-2007
Daved
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.
• 06-26-2007
Joelito
If I was doing this, I'll just loop in the array...
• 06-26-2007
indigo0086
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.