diff options
author | dx <aryadevchavali1@gmail.com> | 2020-05-20 16:24:57 +0100 |
---|---|---|
committer | dx <aryadevchavali1@gmail.com> | 2020-05-20 16:24:57 +0100 |
commit | 1a2d0ffdbfb69a2858fb45facfb18468106edd9a (patch) | |
tree | 78a52eace964ed3e79e37a5bda71288c22333a21 /Converter/src/compiler.c | |
parent | 505a5ac2a4c57d5daa03046366ac38a2e3182b94 (diff) | |
download | mdhtml-1a2d0ffdbfb69a2858fb45facfb18468106edd9a.tar.gz mdhtml-1a2d0ffdbfb69a2858fb45facfb18468106edd9a.tar.bz2 mdhtml-1a2d0ffdbfb69a2858fb45facfb18468106edd9a.zip |
+function to get the lines of some given file
Uses the dynamic array to alleviate the burdens of computing specific
memory sizes. Terminates lines for parsing.
Diffstat (limited to 'Converter/src/compiler.c')
-rw-r--r-- | Converter/src/compiler.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Converter/src/compiler.c b/Converter/src/compiler.c index e2dd74b..ddbe6ff 100644 --- a/Converter/src/compiler.c +++ b/Converter/src/compiler.c @@ -1,4 +1,5 @@ #include "../includes/compiler.h" +#include "../includes/array.h" #include <stdio.h> #include <string.h> @@ -189,3 +190,32 @@ string compile_line(string line, size_t size_of_line, string line_or_source) return compiled_line; } + +char **get_lines(char *filename) +{ + FILE *fp; + char **lines, *line; + array_t *arr; + int i; + + array_init(arr); + + fp = fopen(filename, "r"); + + while(!feof(fp)) + { + // Get line + line = malloc(sizeof(*line) * 1024); + fgets(line, 1024, fp); + + // Terminate line + for (i = 0; line[i] != '\n'; ++i); + line[i] = '\0'; + array_append(arr, line); + } + + lines = (char**)arr->data; + free(arr); + + return lines; +} |