Segmentation fault in C code

The following code prints the message that I need it to print using the for loop and character array seen at the end of this code but a segmentation fault occurs after the loop is done and I cannot figure out what the cause is.

Answers

A segmentation fault occurs when you try to access memory that does not belong to your program. This typically happens by the following means:

By dereferencing a pointer that points to a memory location that does not belong to your program. This can be a NULL pointer, a pointer whose associated memory has already been freed, or a pointer that is not initialized.

By accessing an array element beyond the boundaries of the array.

Because you do not use any pointers, I suggest concentrating on the second item. Check whether the index is always >= 0 and < 16. An assert() before each access to the array will help you.