My program counts the occurrence of each digit from 0 to 9 in a string. It seems to me that i have done everything correctly, but a problem still persists.
int main(){
string word = "23456745";
int* ReturnArray = count(word);
for(int i =0; i < 10; i++){
cout << i << ": " << ReturnArray[i] << " \n";
}
delete [] ReturnArray;
return 0;
}
int* count(const string& s){
int length = s.length();
int* array = new int(10);
int counter =0;
for(int j = 0 ; j < 10 ; j++) {
for(int i = 0 ; i < length ; i++) {
char character = s[i];
int value = static_cast<int>(character -'0');
if(value == j)
counter++;
}
array[j] = counter;
counter = 0;
}
return array;
}