Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2014 06:47
Show Gist options
  • Save anonymous/c9b96fbbb44f665a121d to your computer and use it in GitHub Desktop.
Save anonymous/c9b96fbbb44f665a121d 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 } };
int nb_field = 0;
size_t i;
puts("{");
for (i = 0; i < (sizeof fields/sizeof fields[0]); ++i) {
if (fields[i].is_here) {
if (nb_field != 0)
puts(",");
printf("\t%s", fields[i].field);
nb_field++;
}
}
puts("\n}");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment