Skip to content

Instantly share code, notes, and snippets.

@gon1332
Last active August 29, 2015 14:04
Show Gist options
  • Save gon1332/7d4847969957c9c27a4c to your computer and use it in GitHub Desktop.
Save gon1332/7d4847969957c9c27a4c to your computer and use it in GitHub Desktop.
Print separated data in C the right way
#include <stdio.h>
void generate_initializer(char *string, const char *separator)
{
static char *sep = "";
printf("%s%s", sep, string);
sep = separator;
}
int main(void)
{
char *arr[] = {"10", "23", "12", "43", "23", "1", "23"};
int i = -1;
while (i++ < 6)
generate_initializer(arr[i], ", ");
puts("");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment