Skip to content

Instantly share code, notes, and snippets.

@kaworu
Forked from anonymous/gist:c9b96fbbb44f665a121d
Last active August 29, 2015 14:06
Show Gist options
  • Save kaworu/9f143adb781af1dc2194 to your computer and use it in GitHub Desktop.
Save kaworu/9f143adb781af1dc2194 to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct json_field {
const char* field;
int is_here;
};
int main(void)
{
/* Met 0 ou 1 pour simuler l'absence/présence du champ */
struct json_field fields[] = { { "'fsname': 'dev'", 1 },
{ "'percentage_used': '0.000000'", 1 },
{ "'mount_point': 'dev/'", 1 } };
size_t i;
printf("{");
const char *comma = "";
for (i = 0; i < (sizeof fields/sizeof fields[0]); ++i) {
if (fields[i].is_here) {
printf("%s\n\t%s", comma, fields[i].field);
comma = ",";
}
}
puts("\n}");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment