I have started by programming with Golang, and things looked easy.Then I stumbled on JSON parser of C (JSMN) so that I can try CGO.
Here's the code lines (11 and 46) from this example:
static const char *JSON_STRING =
"{\"user\": \"johndoe\", \"admin\": false, \"uid\": 1000,\n "
"\"groups\": [\"users\", \"wheel\", \"audio\", \"video\"]}";
printf("- User: %.*s\n", t[i+1].end-t[i+1].start, JSON_STRING + t[i+1].start);
This gives me result:
"- User: johndoe"
I am new to C. I want to get the value "johndoe" into a variable. I tried below code its giving me NULL
:
int c = 0;
char sub[1000];
while (c < (t[i+1].end-t[i+1].start) ) {
sub[c] = JSON_STRING[t[i+1].start+c-1];
c++;
}
sub[c] = '\0';
Output:
"-User: null "
How can I do that? Thanks!