json.c 782 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * File: json.c
  3. * Author: Arthur Brandao
  4. *
  5. * Created on 24 novembre 2018
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "json.h"
  10. /* --- Fonctions publiques --- */
  11. void add_json_node(JsonEncoder* this, char* str){
  12. //Création node
  13. JsonNode* node;
  14. node = malloc(sizeof(JsonNode));
  15. //Allocation node
  16. int length = strlen(str) + 1;
  17. node->str = malloc(length * sizeof(char));
  18. memset(node->str, 0, length);
  19. strncpy(node->str, str, length - 1);
  20. //Si 1er node
  21. if(this->head == NULL){
  22. this->head = node;
  23. node->prev = NULL;
  24. } else {
  25. node->prev = this->tail;
  26. node->prev->next = node;
  27. }
  28. this->tail = node;
  29. node->next = NULL;
  30. }
  31. void delete_json_node(JsonNode* node){
  32. free(node->str);
  33. }