Note: I am still pretty new to C.
So I have a pretty overcomplicated program that should output FizzBuzz:
#include <stdio.h>
#include <string.h>
int main() {
char* theArray[] = {"", "", "Fizz", "", "Buzz"};
int size = sizeof(theArray)/sizeof(theArray[0]);
for (int i = 1; i < 100; i++) {
char* output = "";
for (int j = 0; j < size; j++) {
if (i % (j+1) == 0) {
strcat(output, theArray[j]);
}
}
if (output) {
printf("%d", i);
} else {
printf("%s", output);
}
printf("\n");
}
return 0;
}
Compiling this produces no error while running it doesn't produce the desired FizzBuzz but just this error:
Illegal instruction: 4
I tried compiling it with the compiler-flag -mmacosx-version-min=12.0
since that is the version I'm currently on and also -mmacosx-version-min=10.x
, since it is suggested by this question, however, nothing helped.