diff options
author | Ian C <ianc@noddybox.co.uk> | 2018-07-07 13:25:14 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2018-07-07 13:25:14 +0000 |
commit | a4e7cdec1e832a274ff2e176ae2e16a566388da8 (patch) | |
tree | d763830db7a694f9890206cbbbe39e51a32eced0 | |
parent | 82f2f0438c354883bfd42eeabf30b44826f1ded9 (diff) |
Initial checkin. Argument parsing done.
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | codeword.c | 83 |
2 files changed, 88 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c8c9ae1 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +codeword: codeword.c + $(CC) -o codeword codeword.c + +clean: + rm -f codeword diff --git a/codeword.c b/codeword.c new file mode 100644 index 0000000..7b215a9 --- /dev/null +++ b/codeword.c @@ -0,0 +1,83 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +typedef struct +{ + int is_letter; + int number; + char letter; +} Character; + +static void Chomp(char *p) +{ + size_t l = strlen(p); + + while (l && p[l-1] == '\n') + { + p[--l] = 0; + } +} + +static void Error(const char *p) +{ + perror(p); + exit(EXIT_FAILURE); +} + +int main(int argc, char *argv[]) +{ + int no_chars; + Character *chars; + int f; + FILE *fp; + char buff[1024]; + + if (argc < 3) + { + fprintf(stderr, "usage: %s wordlist <letter or number> ...\n", argv[0]); + exit(EXIT_FAILURE); + } + + no_chars = argc - 2; + chars = malloc(sizeof *chars * no_chars); + + if (!chars) + { + Error("malloc"); + } + + for(f = 0; f < no_chars; f++) + { + int i; + + i = atoi(argv[f+2]); + + if (i == 0) + { + chars[f].is_letter = 1; + chars[f].letter = argv[f+2][0]; + chars[f].number = 0; + } + else + { + chars[f].is_letter = 0; + chars[f].number = i; + chars[f].letter = 0; + } + } + + fp = fopen(argv[1], "r"); + + if (!fp) + { + Error(argv[1]); + } + + while(fgets(buff, sizeof buff, fp)) + { + } + + return EXIT_SUCCESS; +} |