Skip to content

Instantly share code, notes, and snippets.

@lukateras
Last active November 29, 2021 01:24
Show Gist options
  • Save lukateras/7afbcc6c42a821423d00 to your computer and use it in GitHub Desktop.
Save lukateras/7afbcc6c42a821423d00 to your computer and use it in GitHub Desktop.
Overengineered fizzbuzz in C
#include <stdio.h>
#include <string.h>
#define BUFLEN 9
int main() {
char buf[BUFLEN];
FILE *stream = fmemopen(&buf, BUFLEN, "w");
if (stream == NULL) {
perror("couldn't open stream");
return 1;
}
setbuf(stream, NULL);
for (unsigned short i = 1; i <= 100; i++) {
bzero(&buf, BUFLEN);
rewind(stream);
if (i % 3 == 0) fputs("Fizz", stream);
if (i % 5 == 0) fputs("Buzz", stream);
if (!*buf) fprintf(stream, "%hu", i);
puts(buf);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment