Im getting the error "Segmentation fault (core dumped)" when I run this program. I am new to c programming so its probably something stupid but i cant figure it out.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void swap(char *x, char *y){
    char temp = *x;
    *x=*y;
    *y=temp;
}
char** getPermutations(char *string){
    int length = strlen(string);
    int startIndex = 0;
    int endIndex = length - 1;
    if(startIndex == endIndex){
            printf("%s\n", string);
    }else{
            for(int j = startIndex; j<=endIndex; j++){
                    swap((string + startIndex),(string + j));
                    getPermutations(string);
                    swap((string+startIndex),(string+j));
            }  
    }    
}
int main(int argc, char *argv[]){
     if(argc>2){
            printf("\nToo Many arguments\n");
            exit(0);
    }else{
            printf("%s",argv[1]);
            char * str = malloc(strlen(argv[1]) + 1);
            strcpy(str,argv[1]);
            getPermutations(str);
    }
}
 
     
    