Hello. Your problem is that you are going out of bounds with that array.
n = 2, so the string array 'A' has 2 strings. Position 0, and position 1. Later you access n-1, which ends up being 3 - 1 which = 2. There is no position 2 in the array, so it crashes.