Hello,
I am having a problem with the output for my sub-string generator program.
input: abc
desired output: a, b, c, ab, bc, ac, abc
current output: abc, abcc, abcb, abcbc, abca, abcac, abcab, abcabc
I am sure the error is right in front of me, but I have been having alot of difficulty figuring out how to pass the input to the "find_combinations" function.
thanks!
#include <iostream>
#include <string>
using namespace std;
int count = 0;
int find_combinations(string sofar, string full_str){
if(full_str.length() == 0 ){
cout << sofar << endl;
++count;
}
else{
char temp_str = full_str[0];
full_str = full_str.substr(1);
find_combinations(sofar , full_str);
sofar.push_back(temp_str);
find_combinations(sofar , full_str);
}
return count;
}
int main(){
cout << "Enter word for possible combinations: ";
string user_input;
cin >> user_input;
string post_input;
post_input = user_input;
find_combinations(user_input, post_input);
}