Change
scanf("%d[\n]",&n);
to
scanf("%d\n",&n);
The reason that your original code does not work is because scanf wants to read an integer, a "[", a "\n" and a "]". So when you input an integer followed by a "\n", scanf only takes the integer(because it expects to see a "["). Then the getchar will simply take the remaining "\n". That's why your getchar() seems not working.
Hope it is helpful to you!