Finding n-th permutation with repetition of a string ANSI C