A little trouble implementing a blur filter

I've got the concept of blurring an image down, but I have not a clue as to how to implement it. I know it starts with manipulation of a pixel and it's eight neighbors. I'm using a .pgm as an example, so manipulating integers is the goal.

c c c

c 1 c

c c c <-------so that's the problem

Now take the mean of the surrounding pixels right?

I've also seen it as 1/4 * original pixel + 1/8 * sum of horizontal and vertical pixels + 1/16 * sum of diagonal pixels.

Can someone lead me down the right track on coding this stuff?

Also, isn't there a problem with the extreme edges if the algorithm is made like above? So you'd end up with

- - - - -

- c c c -

- c 1 c -

- c c c -

- - - - - with the hyphens being unfiltered?

Any help if greatly appreciated