#include int dvsr; long int cntr=0; void showit(char istring[]) { printf(istring); cntr++; if (!(cntr % dvsr)) putchar('\n'); else putchar(' '); } int test_set(unsigned char achar, unsigned char *used) { unsigned int quo, rem, target; int i; quo = achar >> 3; rem = achar & 7; for (target = 128; rem; target >>= 1,rem--); if (used[quo] & target) return 0; used[quo] |= target; return 1; } void cryp (char *istring,int l, int r) { int i, j, l_one; char *ostring; unsigned char *used; if (l == r) showit(istring); else { ostring=(char *)calloc(r+1,sizeof(char)); used =(unsigned char *)calloc(16,sizeof(char)); strcpy(ostring,istring); l_one = l + 1; cryp(ostring,l_one,r); /*First call as is */ test_set(istring[l], used); for (i=l_one; i < r;i++) if (test_set(istring[i],used)) { strcpy(ostring,istring); /*Reinitialize*/ ostring[l] = istring[i]; for (j=l_one; j <= r;j++) if (j <= i) ostring[j]= istring[j - 1]; else ostring[j]= istring[j]; cryp(ostring, l_one, r); } /*Not used yet for loop */ free(ostring); free(used); } /* The else recursion loop */ } /*End procedure*/ void main(int argc,char *argv[]) { char temp, mainstr[20]; int i, j, strleng=0; if (argc > 1) strcpy(mainstr,argv[1]); else { fprintf(stderr,"Enter character string --> "); gets(mainstr); } for (i=0;mainstr[i];i++) if (mainstr[i] < ' ') { mainstr[i]=0; break; } if ((strleng= strlen(mainstr)) > 19) { fprintf(stderr,"\aString too long %d\n",strleng); exit(1); } dvsr = 80 / (strleng + 1); for (i=0; i < strleng - 1;i++) for (j=i+1; j < strleng; j++) if (mainstr[i] > mainstr[j]) { temp = mainstr[i]; mainstr[i] = mainstr[j]; mainstr[j] = temp; } cryp(mainstr, 0, strleng); printf("\n\nThere were %ld entries",cntr); fprintf(stderr,"\nThere were %ld entries\n",cntr); }