diff options
Diffstat (limited to 'src/echo.c')
-rw-r--r-- | src/echo.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 <stdlib.h> +#include <stdio.h> +#include "echo.h" +#include <string.h> +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 +} |