Thanks. I modified the two while loops according to your guidance, and now there are no segfaults.
True, the program still does nothing (it dosent write out anything, it just ends). I guess this is an improvement.
Okay, i managed to fix my code, so it now writes out all permutations. If anyone needs it:
Code:
#include <stdio.h>
#include <string.h>
int main(argc,argv)
int argc;
char *argv[];
{
int l;
char sk[20];
sk[0]='\0';
if (l <= 19)
permutal(sk,argv[1],0,strlen(argv[1]),strlen(argv[1]));
}
permutal(sk,s,i,l,l2)
char sk[20],s[20];
int i,l,l2;
{
int j=0;
char ideiglenes,s2[20];
strcpy(s2,s);
for (j=0;j<l;j++)
{
sk[i]=s2[j];
sk[i+1]='\0';
ideiglenes=s2[0];
s2[0]=s2[j];
s2[j]=ideiglenes;
if (i != l2)
permutal(sk,&s2[1],i+1,l-1,l2);
if (l == 1)
{
printf("%s\n",sk);
}
ideiglenes=s2[0];
s2[0]=s2[j];
s2[j]=ideiglenes;
}
}