Hi guys! First post haha.
I'm kind of new to C so if I do anything really silly please let me know (C-related or forum related).
So I have a 2-d array and I need to check the neighbouring cells are within the bounds of the array.
For example, a 10x10 array should have max 8 neighbouring cells and at least 3.
For now, I'm trying to do some arithmetic on the neighbouring cells but I'm having trouble since my loop keeps accessing cells outside of my defined array.
This obviously happens at the cells on the sides and corner points, where I'm not getting 8 cells around the targetted cell.
Is there a way to check if the cell is outside the array?
This is the code I'm using to read the array right now within 2 for loops.tmp[r-1][c-1], tmp[r-1][c],
tmp[r-1][c+1],
tmp[r][c-1],
tmp[r][c],
tmp[r][c+1],
tmp[r+1][c-1],
tmp[r+1][c],
tmp[r+1][c+1]);
I know I need an if loop, but not sure how to go about it (I tried saying:
"if r!=0" but then got lost...
Any help would be great! Thanks