C Permutations

#include "stdio.h"
#include 
#include 

/*
  Author: Fernando Zamora
  Date: 9 Feb 2017

   A permutation is composed of a set of items.  I use the term "set" loosely.
   By definition a set has distinct items.  In my case it is simply a bag of items that can be rearranged.  In a typical set the factorial math works but in a bag the math is off due to repeated values. 
   For the purpose of this code snippet we focus on the idea that although two of the same values can be arranged we only focus on the one permutation since from a realistic perspective the two permutaions are the same (e.g. a,a,b is the same as a,a,b where a=1, a=2, and b=3)
   
   {1,2,3} 3! 3x2x1 1,2,3 132 213 231 312 321
   {1,2,3,4} 4! 4x3x2 24
   {1,2,3,4,5} 5x4x3x2 
   
*/
#define TRUE 1 
#define FALSE 0
#define UNDEF -1

/*
  brute force bubble sort
*/
char* sort(char* target){
  
  int length = strlen(target);
  int swapped = 0;
  int temporaryValue = 0;
  do{
    swapped = 0;
    
    for(int i=0;i<(length-1);i++){
      if(target[i] > target[i+1]){
        temporaryValue = target[i];
        target[i] = target[i+1];
        target[i+1] = temporaryValue;
        swapped = 1;
      }
    }
  }
  while(swapped != 0);
  
  return target;
}

int isPermutationOf(const char *s1, const char *s2){
  
  char* ps1 ; // = malloc(sizeof(s1[0]) * strlen(s1));
  char* ps2 ; //= malloc(sizeof(s2[0]) * strlen(s2));
  
  if(strlen(s1) == 0 || strlen(s2) == 0){
    return FALSE;
  }
  
  if(strlen(s1) != strlen(s2)){
    return FALSE;
  }

  ps1 = malloc(sizeof(s1[0]) * strlen(s1));
  ps2 = malloc(sizeof(s2[0]) * strlen(s2));
  
  if(ps1 == NULL || ps2 == NULL){
    return UNDEF;
  }

  strcpy(ps1, s1);
  strcpy(ps2, s2);
  
  sort(ps1);
  sort(ps2);

  if(strcmp(ps1, ps2) == 0){
    free(ps1);
    free(ps2);
    return TRUE;
  }
  
  free(ps1);
  free(ps2);
  return FALSE;  
}

void test(int expected, int actual, const char* testName){
  if(expected == actual){
    printf("\n%s PASSED", testName);
  }
  else{
    printf("\n%s FAILED expected: %d actual: %d", testName, expected, actual);
  }
}



int main(void) {
  
  char mystr[4] = "bac";
  printf("\nSorted bac %s", sort(mystr));
  
  test(TRUE, isPermutationOf("123", "123"), "123=>123");
  test(TRUE, isPermutationOf("123", "321"), "123=>321");
  test(TRUE, isPermutationOf("abc", "cab"), "abc=>cab");
  test(FALSE, isPermutationOf("123", "124"), "123=>124");
  test(TRUE, isPermutationOf("abcdefghijk", "kjihgfedcba"), "kjihgfedcba");
  test(FALSE, isPermutationOf("", "a"), "1 is empty");
  test(FALSE, isPermutationOf("a", ""), "2 is empty");
  test(FALSE, isPermutationOf("", ""), "1 and 2 are emtpy");
  
  
  return 0;
}