user2093028
user2093028

Reputation: 19

Generating All List (permuting)

I'm quite unsure why my code does this when I type 6 or more numbers/characters that it only display some of the output. (I know that numbers/characters does not affect anything).

For example if I type cat it'll list all the possible variations: cat cta act atc tac tca

But when I type in 123456 (or any 6+ lettered strings): It start displaying at 462513-612345 (if you know what I mean). What happened to the rest (123456-462513)?

    #include <stdio.h>
    #include <string.h>

    void swap (char *X, char *Y)
    {
      char Z;
      Z = *X;
      *X = *Y;
      *Y = Z;
    }

    void mixmatch (char *A, int i, int n)
    {
      int j;
      if (i == n)
         printf("%s\n", A);
      else
      {
         for (j = i; j <= n; j++)
         {
            swap((A+i), (A+j));
            mixmatch(A, i+1, n);
            swap((A+i), (A+j));
         }
      }
    }

    int main()
    {
       char A[100];
       printf ("Enter the string/set of numbers: ");
       gets(A);

       int k;
       k=strlen(A);
       mixmatch(A, 0, k-1);

    return 0;
    }

Upvotes: 2

Views: 166

Answers (2)

Aniket Inge
Aniket Inge

Reputation: 25723

The problem is not your code, the problem is the windows cmd.exe does not have enough buffer to show you all the permutations.

I tried with cygwin and it works flawlessly.

Here are the screenshots to prove it:

with cmd.exe

enter image description here

with cygwin

enter image description here

Upvotes: 1

Bernd Elkemann
Bernd Elkemann

Reputation: 23560

Aniket is right.

Here's what to do:

You can increase cmd.exe's storage using the top-left menu's settings. Set buffer height to 9999.

Upvotes: 0

Related Questions