diff options
Diffstat (limited to 'words-misc/permutations.c')
-rw-r--r-- | words-misc/permutations.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/words-misc/permutations.c b/words-misc/permutations.c index 7f6b0ef..13374db 100644 --- a/words-misc/permutations.c +++ b/words-misc/permutations.c @@ -2,32 +2,21 @@ #include <stdlib.h> #include <string.h> -void swap_chr(char*, char*); -void p(char *, size_t, size_t); -void die_help(const char*); - -int main(int argc, char **argv) -{ - if (argc != 2) - die_help(argv[0]); - - p(argv[1], strlen(argv[1]), 0); - - return 0; -} - -void die_help(const char* argv0) { +void +die_help(const char* argv0) { fprintf(stderr, "Usage: %s <word>\n", argv0); exit(1); } -void swap_chr(char *a, char *b) { +void +swap_chr(char *a, char *b) { char t = *a; *a = *b; *b = t; } -void p(char *string, size_t x, size_t i) { +void +p(char *string, size_t x, size_t i) { size_t j = 0; if (i == x) { @@ -41,3 +30,14 @@ void p(char *string, size_t x, size_t i) { swap_chr(&string[i], &string[j]); } } + +int +main(int argc, char **argv) +{ + if (argc != 2) + die_help(argv[0]); + + p(argv[1], strlen(argv[1]), 0); + + return 0; +} |