In addition to what @janos said:
Your formatting style looks weird. This is because in mvaddch(0,x - 1,'#') there is plenty of space around the - operator, but none around the ,. This commonly suggests that the , binds more tightly than the -, which is wrong.
So either use no space at all oreither use no space at all or use a space after the comma as well.