diff options
author | thing 1 <thing1@seacrossedlovers.xyz> | 2024-11-14 08:11:18 +0000 |
---|---|---|
committer | thing 1 <thing1@seacrossedlovers.xyz> | 2024-11-14 08:11:18 +0000 |
commit | 2e1ccff01cf89539b621ac786898229307847f4b (patch) | |
tree | 88f91a94a58e6452288ed3145de51cb73c9f249b /comp/lucas-standen-NEA/code2/parser.c | |
parent | bca6aeb86a3ca5d33cf1f33a81fcce2220d97a5a (diff) |
made too many changes to note
Diffstat (limited to 'comp/lucas-standen-NEA/code2/parser.c')
-rw-r--r-- | comp/lucas-standen-NEA/code2/parser.c | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/comp/lucas-standen-NEA/code2/parser.c b/comp/lucas-standen-NEA/code2/parser.c deleted file mode 100644 index a84291b..0000000 --- a/comp/lucas-standen-NEA/code2/parser.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "util.h" - -typedef struct strings { - char **strs; - int count; -} strings; - -//# counts the number of times c ocurrs in s -int countChars(char *s, char c){ - int count = 0; - for (int i = 0; i < strlen(s); i++){ - if (s[i] == c) count++; - } - return count; -} - -//# returns an array of strings (type strings) of the file contents, split by line -strings *parse(FILE *f){ - strings *strs = malloc(sizeof(strings)); - strs->strs = malloc(sizeof(char **)); - - char *line = alloca(256); - int count = 0; - while (fgets(line, 256, f) != NULL){ - if (line[0] != '\n' && line[0] != '/'){ - while (line[0] == '\t') line++; - line[strlen(line)-1] = '\0'; - strs->strs[count] = malloc(256); - memcpy(strs->strs[count], line, 256); - count++; - } - } - strs->count = count; - - return strs; -} |