fork(4) download
  1. #include <jansson.h>
  2. #include <cairo.h>
  3.  
  4. int main() {
  5. json_t *root;
  6. json_error_t error;
  7. root = json_load_file("test.json", 0, &error);
  8. if(!root){
  9. fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
  10. return 1;
  11. }
  12. printf("Eh um objeto: %d\n", json_is_object(root));
  13.  
  14. json_t * jidade = json_object_get(root, "idade");
  15. int idade = json_number_value(jidade);
  16. printf("Idade: %d\n", idade);
  17.  
  18. json_t * jtest = json_object_get(root, "test");
  19. json_t * jnovo = json_object_get(jtest, "novo");
  20. int novo = json_number_value(jnovo);
  21. printf("Valor real: %d\n", novo);
  22.  
  23. json_t * jarray = json_object_get(jtest, "array");
  24. printf("Tamanho do array: %ld\n", json_array_size(jarray));
  25. for(int i = 0; i < json_array_size(jarray); ++i){
  26. printf("Index[%d]: %.0lf\n", i, json_number_value(json_array_get(jarray, i)));
  27. }
  28. json_t * jarray2 = json_object_get(jtest, "array2");
  29. json_t * blah = json_array_get(jarray2, 0);
  30. printf("Key1: %s\n", json_string_value(json_object_get(blah, "key1")));
  31. return 0;
  32. }
  33.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:21: error: jansson.h: No such file or directory
prog.c:2:19: error: cairo.h: No such file or directory
prog.c: In function ‘main’:
prog.c:5: error: ‘json_t’ undeclared (first use in this function)
prog.c:5: error: (Each undeclared identifier is reported only once
prog.c:5: error: for each function it appears in.)
prog.c:5: error: ‘root’ undeclared (first use in this function)
prog.c:6: error: ‘json_error_t’ undeclared (first use in this function)
prog.c:6: error: expected ‘;’ before ‘error’
prog.c:7: warning: implicit declaration of function ‘json_load_file’
prog.c:7: error: ‘error’ undeclared (first use in this function)
prog.c:9: warning: implicit declaration of function ‘fprintf’
prog.c:9: warning: incompatible implicit declaration of built-in function ‘fprintf’
prog.c:9: error: ‘stderr’ undeclared (first use in this function)
prog.c:12: warning: implicit declaration of function ‘printf’
prog.c:12: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:12: warning: implicit declaration of function ‘json_is_object’
prog.c:14: error: ‘jidade’ undeclared (first use in this function)
prog.c:14: warning: implicit declaration of function ‘json_object_get’
prog.c:15: warning: implicit declaration of function ‘json_number_value’
prog.c:18: error: ‘jtest’ undeclared (first use in this function)
prog.c:19: error: ‘jnovo’ undeclared (first use in this function)
prog.c:23: error: ‘jarray’ undeclared (first use in this function)
prog.c:24: warning: implicit declaration of function ‘json_array_size’
prog.c:24: warning: format ‘%ld’ expects type ‘long int’, but argument 2 has type ‘int’
prog.c:25: error: ‘for’ loop initial declaration used outside C99 mode
prog.c:26: warning: implicit declaration of function ‘json_array_get’
prog.c:26: warning: format ‘%.0lf’ expects type ‘double’, but argument 3 has type ‘int’
prog.c:28: error: ‘jarray2’ undeclared (first use in this function)
prog.c:29: error: ‘blah’ undeclared (first use in this function)
prog.c:30: warning: implicit declaration of function ‘json_string_value’
prog.c:30: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
stdout
Standard output is empty