I solved the problem. I changed the method a bit but that really doesn't change anything.
I post the code in case someone other has the same problem. Google often gives me links to forums with unanswered questions and I hate it.
This is an example on 256 color bitmaps. 24-bit should be a bit different. Here's the code anyway:
int add1, add2;
fread(&bmpHeader, sizeof(BITMAPFILEHEADER), 1, bmp);
fread(&bmpInfo, sizeof(BITMAPINFOHEADER), 1, bmp);
add1=bmpInfo.biWidth%4; //The bytes are situated in the line as arrays with a size of 4 multiples. If there are less than a 4 multiple bytes, zeros are added to the end.
add2=bmpInfo.biHeight*add1;//As there are some zeros in included, I have to read some more bytes that just the pixel count. I calculate how much more.
fread(&rgb, sizeof(RGBQUAD), 256, bmp); // Reading all 256 colors
fseek(bmp, bmpHeader.bfOffBits, SEEK_SET); //Just in case I'm somehow in the wrong position, although the pixel data should follow anyway.
fread(&pixel, sizeof(char), pixel_count+add2, bmp);
//Writing the data to the text file
for(int i=0; i<bmpInfo.biHeight; i++)
for(int j=0; j<bmpInfo.biWidth+add1; j++)
if(j<bmpInfo.biWidth) fprintf(data, "%.2x%.2x%.2x\n", rgb[pixel[(pixel_count+add2-(bmpInfo.biWidth+add)*(i+1))+j]].rgbRed, rgb[pixel[(pixel_count+add2-(bmpInfo.biWidth+add)*(i+1))+j]].rgbGreen, rgb[pixel[(pixel_count+add2-(bmpInfo.biWidth+add)*(i+1))+j]].rgbBlue);
//The bitmap data gives me the number of its color in the color array, so I print the colors instead of that quite useless number. It's a bit complicated as the bitmap data starts from the lower right corner and I would like it start from the upper corner.