I\'m trying to load a tga/bmp file. This works fine, but the end result looks like this:
I interpreted this question as: "How do I load a TGA file? What I tried didn't work."
99% of the time the right answer is not going to be "copy and paste this function that loads TGA files which I wrote". That is the approach that the accepted answer is taking. But if you want a solution that not only works, but will be more maintainable and more likely to be fixed if it contains bugs, then it is better to use a library. Rolling your own solution is a fine way to learn and should be encouraged, but it is not usually the best or easiest way to get something done.
Use a real image library instead of trying to roll your own function to read them. Your assumptions on the data format are not correct, so the data you are getting is bunk. You appear to be assuming that the data is a 128x128 pixel raw.
http://tgalib.sourceforge.net/ is an open source library for reading TGA files. Use it, for example.
https://github.com/nothings/stb is another alternative with a more liberal (public domain) license that in addition to loading TGA files has a lot of other things that would come in handy for OpenGL programs.
Both libraries are a better choice than copy-pasting code you found online.