I'm not sure why I'm getting Segmentation Fault: 11
when trying to compile this small C file:
#include <stdio.h>
#define MIN 97
#define MAX 122
#define DIFF 32
int main()
{
int c = EOF;
int i, j;
int arr[MAX - MIN];
for(i=MIN; i<=MAX; i++)
arr[i] = 0;
while((c = getchar()) != EOF) {
if(c >= MIN)
++arr[c];
else
++arr[c + DIFF];
}
for(i=MIN; i<=MAX; i++) {
printf("|%c|", i);
for(j=1; j<=arr[i]; j++)
putchar('-');
putchar('\n');
}
return 0;
}
I'm using Apple's built-in cc
which is just Clang/Apple LLVM 10.0.0
This file compiles just fine on macOS 10.13.6, and I don't have any problems compiling any other C files/programs on 10.14; it's just this one file. From my beginner's point of view, this seems like a bug with the OS.
EDIT: This program is a slightly modified example from a K&R exercise I found here