A nice program

I just had an idea for a nice program capable of showing ALL of the possible combinations of letters in an user-specified word, here is the source code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;

const int MAX_CHARS = 20, MAX_WORDS = 100;

int main(){

    char string[MAX_CHARS];
    char fileName[MAX_CHARS];
    
    cout << "Inserir palavra/frase: "; cin.getline(string, MAX_CHARS);
    cout << "Inserir nome do ficheiro(ou path) onde guardar resultados: ";cin >> setw(MAX_CHARS) >> fileName;
    ofstream output(fileName);
    for(int i = 0; i < strlen(string); ++i){
            for(int j = strlen(string)-1; j > 0; --j){
                    char tmp = string[i];                    
                    string[i] = string[j];
                    string[j] = tmp;
                    
                    output << string << endl;
                    
            }
    }
    output.close();
    cout << "Ficheiros guardados com sucesso!" << endl;
    system("pause");
}


I believe it does not show all the combinations...plus, it sometimes creates repetitions, how do I solve that?

Best Regards

PS: I asked this on my previous post, however I didn't got any answers, what is a(the?) buffer?
A buffer is a temporary cache where data is stored until it's extracted.
For example, the back buffer of a game contains the next "image" you'll see, and most games render their graphics by simply "flipping" the back buffer to the screen. This way, smooth animations are possible to achieve. Just like drawing something on the back of a sheet of paper and then flipping it around.
Topic archived. No new replies allowed.