From a4e7cdec1e832a274ff2e176ae2e16a566388da8 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 7 Jul 2018 13:25:14 +0000 Subject: Initial checkin. Argument parsing done. --- codeword.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 codeword.c (limited to 'codeword.c') 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 +#include +#include +#include + +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 ...\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; +} -- cgit v1.2.3