Choose file to parse from CLI arguments

This commit is contained in:
olemorud
2023-04-22 22:37:17 +02:00
parent dc4e39af6c
commit 9f66f4aff9
2 changed files with 9 additions and 5 deletions

View File

@@ -2,7 +2,7 @@
# C JSON Parser
Just a simple project to practice writing parsers.
Not guaranteed to be safe or efficient.
Not guaranteed to be safe, reliable or efficient.
## Usage
@@ -16,7 +16,7 @@ To make a debug build just run `make`.
### Run
```sh
./bin/{release|debug}/json_parser
./bin/{release|debug}/json_parser sample.json
```
## Limitations

View File

@@ -4,13 +4,17 @@
#include "util.h"
#include <stdlib.h> // atexit
#include <unistd.h> // _exit
#include <err.h> // errx
int main()
int main(int argc, char* argv[])
{
if (argc != 2) {
errx(EXIT_FAILURE, "Usage: %s <file>", argv[0]);
}
atexit(print_trace);
FILE* fp = fopen("sample.json", "r");
FILE* fp = fopen(argv[1], "r");
volatile struct json_value x = parse_json_value(fp);