-
-
Save whitglint/71adc75e77a0672e0ccf85c5eb76dd46 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
| #include <stdlib.h> | |
| static const size_t sizeToAlloc = sizeof("9223372036854775807"); | |
| char** fizzBuzz(int n, int* returnSize) { | |
| char** ret = calloc(n, sizeof(char*)); | |
| *returnSize = n; | |
| char* sp; | |
| for (int i = 1; i <= n; ++i) { | |
| sp = *(ret + (i - 1)) = calloc(1, sizeToAlloc); | |
| (i % 5 && i % 3) ? sprintf(sp, "%d", i) : sprintf(sp, "%s%s", (i % 3) ? "" : "Fizz", (i % 5) ? "" : "Buzz"); | |
| } | |
| return ret; | |
| } | |
| int main() { | |
| int n = 15; | |
| int returnSize; | |
| char **res = fizzBuzz(n, &returnSize); | |
| for (int i = 0; i < n; ++i) { | |
| printf("%s\n", res[i]); | |
| free(res[i]); | |
| } | |
| free(res); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment