#include <iostream>
#include <string>
#include <vector>
using namespace std;
void converter(vector<char>keypad[],int num[], int index, string result, int size_of_num){
if(index == size_of_num){
cout << result << " ";
return;
}
int digit = num[index];
int size_of_keypad = keypad[digit].size();
for(int i=0; i < size_of_keypad; i++){
converter(keypad, num, index + 1, result + keypad[digit][i], size_of_num);
}
}
int main(){
vector <char> keypad[] = {
{},{},{'a','b','c'},
{'d','e','f'},
{'g','h','i'},
{'j','k','l'},
{'m','n','o'},
{'p','q','r','s'},
{'t','u','v'},
{'w','x','y','z'}};
int numbers[] = {2,3,4};
int size_of_num = sizeof(numbers);
converter(keypad, numbers, 0, string (""), size_of_num );
return 0;
}
I tried running this code, which was to transfrom phone numbers into words. I used vector in this problem with a reucrsive function. But I am not sure if its just the memory overflowing or just totally something else.
I tried and search online in order to solve this and I found the correct code, but everything they were doing was the same and the only thing that was differnt were the varible names. I just couldn't figure out whats wrong.