Edge detection with sobel operator/mask

Hi. I'm trying to write little program that is able to detect edges. But it's not working correctly. I want to detect edges and get orientation (angle) of this egdes. So I'm using Sobel Mask/Operator to do this.

The Sobel operator performs a 2-D spatial gradient measurement on an image. Typically it is used to find the approximate absolute gradient magnitude at each point in an input grayscale image. The Sobel edge detector uses a pair of 3x3 convolution masks, one estimating the gradient in the x-direction (columns) and the other estimating the gradient in the y-direction (rows).