This seems like the same idea as Sivan's, but maybe it helps you or gives you more ideas (ps this example is in c# but my quess is that it is possible in c too):

http://stackoverflow.com/questions/6020406/travel-through-pixels-in-bmp