fizzbuzz

void fizzbuzz_with_memory_management(int start, int end) { int i; char * fzbz; for (i = start; i <= end; i++) { fzbz = (char *) malloc(9 * sizeof(char)); //: fizzbuzz\0 if (i % 3 == 0) strcat(fzbz,"fizz"); if (i % 5 == 0) strcat(fzbz,"buzz"); if(strlen(fzbz) != 0) printf("%s\n", fzbz); else printf("%d\n", i); free(fzbz); } }
yes yes, done many times before.. but a thought occurred to me~

If the purpose of fizzbuzz is to demonstrate you at least know how to code, why not show them you know how to handle memory too?

This may not be 100% optimized, feel free to leave a comment on how to further better it !
(note: as of last test, this is slower than the if/elseif/elseif/else generic [3:5:(3&5):else] fizzbuzz by a tad bit)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.