This is the first time I have recoded in C for several years and I would like to know how clean my code is.
#include <stdio.h>
#include <string.h>
#define EXIT_SUCCESS 0
void fizzbuzz(int n) {
char result[9] = ""; // strlen("fizzbuzz") + 1 == 9
if (n % 3 == 0) strcat(result, "fizz");
if (n % 5 == 0) strcat(result, "buzz");
if (!*result) sprintf(result, "%d", n);
printf("%s\n", result);
}
int main() {
for (int i = 1; i <= 100; i++) fizzbuzz(i);
return EXIT_SUCCESS;
}
I know that I could include stdlib so as not to have to define EXIT_SUCCESS myself, but as I only needed this constant, it's a little clearer and more efficient to do this I think.