The videos in the Sensing > Line Tracking section of the ROBOTC Curriculum do a great job of explaining how line tracking code works:
http://www.education.rec.ri.cmu.edu/pre ... 2_preview/
You'll also find some sample programs in ROBOTC if you go to File > Open Sample Program > Line Follower.