blob: 1efbcda4594fb87975dd726bb33a12e4e56e262d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
}
|