From 711eb1d91832267bdd1fe2bc57eeebba9e637c52 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Wed, 20 Nov 2024 21:11:38 -0800 Subject: init --- src/echo.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/echo.c (limited to 'src/echo.c') diff --git a/src/echo.c b/src/echo.c new file mode 100644 index 0000000..1efbcda --- /dev/null +++ b/src/echo.c @@ -0,0 +1,29 @@ +#include +#include +#include "echo.h" +#include +int main(int argc, char** argv) { + char* path; + if (argc > 0) { + path = argv[1]; + } + else { + exit(0); + } + char* content = read_file(path); + parse(content); +} +char* read_file(char* path) { + FILE* file = fopen(path, "r"); + if (file == NULL) { + printf("file%s does not exist\n", path); + } + fseek(file, 0, SEEK_END); + unsigned long int length = ftell(file); + fseek(file, 0, SEEK_SET); + char* out = malloc((length + 1) * sizeof(char)); + fread(out, length, 1, file); + fclose(file); + out[length] = '\0'; + return out +} -- cgit v1.2.3-70-g09d2