-
-
Save letoh/4da8eb6d1fb3f89c87e6e71b3ff7ad9c to your computer and use it in GitHub Desktop.
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
char** fizzBuzz(int n, int* returnSize) { | |
struct _ { | |
char *rets[n + 1]; | |
char data[0]; | |
} * ret = calloc(sizeof(struct _) + n * 9 + 1, sizeof(char)); | |
*returnSize = n; | |
char * sp = ret->data; | |
for (int i = 1; i <= n; ++i, sp += 9) { | |
ret->rets[i - 1] = sp; | |
(i % 5 && i % 3) | |
? sprintf(sp, "%d", i) | |
: sprintf(sp, "%s%s", (i % 3) | |
? "" | |
: "Fizz", | |
(i % 5) | |
? "" | |
: "Buzz"); | |
} | |
ret->rets[n] = sp; | |
return ret->rets; | |
} |
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
int main(int argc, char *argv[]) | |
{ | |
int size; | |
char **ret = fizzBuzz(15, &size); | |
for (char **p = ret; **p; ++p) | |
printf("%s\n", *p); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment