summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--codeword.c83
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;
+}