-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a printing function + free arrays that are inside another array
- Loading branch information
Showing
6 changed files
with
74 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
CC=gcc | ||
CFILES=src/main.c \ | ||
src/json_types.c \ | ||
src/printing.c \ | ||
src/storage.c | ||
|
||
all: clean json-parser | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <stdio.h> | ||
|
||
#include "storage.h" | ||
|
||
void arr_print(Array *a) | ||
{ | ||
int size = a->size; | ||
for (int i = 0; i < size; ++i) | ||
{ | ||
ArrayLink al = array_get(a, i); | ||
switch (al.type) | ||
{ | ||
case T_STR: | ||
printf("%s\n", al.strv.str ? al.strv.str : ""); | ||
break; | ||
case T_INT: | ||
printf("%d\n", al.integerv); | ||
break; | ||
case T_DOUBLE: | ||
printf("%f\n", al.doublev); | ||
break; | ||
case T_BOOL: | ||
printf("%s\n", al.boolv ? "true" : "false"); | ||
break; | ||
case T_NULL: | ||
printf("null\n"); | ||
break; | ||
case T_ARR: | ||
arr_print(al.arrayv); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef PRINTING_H | ||
#define PRINTING_H | ||
|
||
#include "storage.h" | ||
|
||
void arr_print(Array *a); | ||
|
||
#endif // !PRINTING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters