Now checks str before trying to reverse
C string permutation solution