I want some feedback on the program I developed in C for printing the permutations of a given string.
#include <stdio.h>
bool isUnique(char x[], int y)
{
int i, j;
for (i = 0; i < (y-1); i++)
for (j = i+1; j < y; j++)
if (x[i] == x[j])
return false;
return true;
}
void perm(char a[], char b[], int x, int y)
{
if ((y == x) && isUnique(b,x))
{
b[y] = '\0';
printf("%s\n", b);
}
else
for (int i = 0; i < x; i++)
{
b[y] = a[i];
if (y < x)
perm(a,b,x,y+1);
}
}
int main()
{
char a[] = {'1','2','3','4'}, b[] = {'\0','\0','\0','\0','\0'};
perm(a,b,4,0);
return 0;
}
Also, please tell me where I'm making blunders as far as conventions and good practice are concerned.