Hacker News new | past | comments | ask | show | jobs | submit login

The terminating character is still the closing double quote and not a null, since the library does neither copy out nor alter the input. For example tiny_json replaces the closing quotes to create C strings, but that needs the full file to be in a mutable buffer which can be prohibitive for small controllers reading some config from flash only.





With the "%.*s" format you need no null at the end. It just counts out the characters:

    #include <stdio.h>

    void main()
    {
      char buff[10] = {'R', 'o', 'b', 'o', 't', 't', 'y', 'p', 'e', 's'};
      printf("=>%.*s<=", 4, ((char *)&buff + 3));
    }
prints

    =>otty<=

Ah. Ok. Scanning the length before printing is mandatory then.

@msarnoff had already stipulated that the json lib is returning lengths:

    all the “tokens” are given as byte offsets and lengths

You have to do (a variant of) one or the other, no?



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: