#include <stdlib.h>
#include <unistd.h>

#include <stdio.h> // pour printf uniquement

void print_string(char *str)
{
    while (*str)
        write(1, str++, 1);
    write(1, "\n", 1);
}

void swap(char *a, char *b)
{
    char temp = *a;
    *a = *b;
    *b = temp;
}

void generate_permutations(char *str, int start, int end)
{
    int i = start;
    
    if (start == end)
    {
        print_string(str);
        return;
    }
    while (i <= end)
        {
            swap(&str[start], &str[i]);
            generate_permutations(str, start + 1, end);
            swap(&str[start], &str[i]);
            i++;
        }
}

int main()
{
    char base[] = "ABC";
    
    int len = 0;
    while (base[len])
        len++;
    printf("len vaut: %d \n", len);
    generate_permutations(base, 0, len - 1);
    return (0);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: