I have this code to do permutations of a string.
#include <iostream> 
#include <string.h>
using namespace std;
/* Prototipo de función */
void Permutaciones(char *, int l=0); 
void sort(string scadena[]);
//array global to copy all permutations and later sort
string array[900000];
int m=0;
int main() {
int casos;
cin>>casos; 
char palabra[casos][13];
for(int i=0;i<casos;i++)
    cin>>palabra[i];
for(int i=0;i<casos;i++){
    m=0;
    Permutaciones(palabra[i]);
    sort(array);
}
  sort(array);
system("pause");
return 0;
}
void sort(string scadena[]){
string temp;
for(int i=0;i<m;i++){
    for(int j=i+1;j<m;j++){
        if(scadena[i]>scadena[j]){
            temp=scadena[i];
            scadena[i]=scadena[j];
            scadena[j]=temp;    
        }           
    }
}
for(int i=0;i<m;i++){
    for(int j=1;j<m;j++){
        if(scadena[i]==scadena[j] && j!=i){
            for(int k=j;k <m; k++){
                scadena[k]=scadena[k+1];
            }
            m--;
            j--;
        }
    }
}   
for(int i=0;i<m;i++){
    cout<<scadena[i]<<endl;
}   
}
void Permutaciones(char * cad, int l) {
char c;    /* variable auxiliar para intercambio */
int i, j;  /* variables para bucles */
int n = strlen(cad);
for(i = 0; i < n-l; i++) {
  if(n-l > 2){
    Permutaciones(cad, l+1);
  } 
  else {
        array[m]=cad;
        m++;            
  }
  /* Intercambio de posiciones */
  c = cad[l];
  cad[l] = cad[l+i+1];
  cad[l+i+1] = c;
  if(l+i == n-1) {
     for(j = l; j < n; j++){
        cad[j] = cad[j+1];
     } 
     cad[n] = 0;
  }
 }
}
And the code generates all permutations fine, and later sorted the array and it works fine. But when i am intenting remove the repeated strings, the code show me somethings repeated, and not sorted.
Who can say me what is my error?