diff options
author | David Phillips <david@sighup.nz> | 2017-09-14 21:19:00 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2017-09-14 21:19:00 +1200 |
commit | d0d76324cc17be550ce6c603dd7efb60e97920be (patch) | |
tree | f3a79de975c60ada315344187fcb9f4cfb3dc3a3 /words-misc/permutations.c | |
parent | 5978cc86c5807a7fe36cba8a227c0001ecaa66d6 (diff) | |
download | odds-and-ends-master.tar.xz |
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; +} |