You forgot to include the relevant code.
You probably call your check function with a NULL pointer. This might happen for example if you use argv before checking whether argc is greater than 1 (or here: equals 2), otherwise that array element wouldn't exist, and could have any value.
Some of your conditions need to change. There's no 'between' syntax like in maths, so (0 < j < width-1) won't work in c.
You need to split this into something like (j > 0 && j < width - 1), and make similar changes to other conditions.