Last active
August 29, 2015 14:04
-
-
Save gon1332/7d4847969957c9c27a4c to your computer and use it in GitHub Desktop.
Print separated data in C the right way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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