Here's the code for HMC5883l in C for Raspberry Pi.
Before you start using this code, make sure you have already setup I2c on your Pi. If not please visit the following link and do it right away.: http://www.raspberrypi-spy.co.uk/2014/11/enabling-the-i2c-interface-on-the-raspberry-pi/
Also install WiringPiI2C library if not yet instlled. Get it here: https://projects.drogon.net/raspberry-pi/wiringpi/i2c-library/
Refer the example code. It isn't rocket science.