I am trying to open a 24-bit bitmap file to use as a simple texture in an OpenGL scene, but I cant get past this debug assertion failure that comes up on fseek or fread.

Code:
void loadBMP(char *filename, byte* BitmapP, int* owidth, int* oheight, int max) {
	byte curnt[3];
	int width, height;

	FILE* file1;
	file1 = fopen(filename, "rb");
	fseek(file1, 18, SEEK_SET);
	fread(&width, sizeof(int), (size_t)1, file1);
	fseek(file1, 22, SEEK_SET);
	fread(&height, sizeof(int), (size_t)1, file1);
	*owidth = width;
	*oheight = height;
	fseek(file1, 54, SEEK_SET);
	for(int y=1; y < height + 1; y++){
		for(int x=1; x < width + 1; x++){
			fread((BitmapP + x*(max*3) + y*3), sizeof(byte), (size_t)3, file1);
		}
		fseek(file1, width % 4, SEEK_CUR);
	}
	fclose(file1);
}
I took most of this code from an online tutorial, but I understand what it's doing and can't figure out why its throwing this error. But i think I have a general idea of where its going wrong. There seems to be a bad pointer remaining after fopen thats causing the first fseek to fail.

I followed the debugger into
Code:
file1 = fopen(filename, "rb");
vs shows the variable file with the proper data, which was "metalt.bmp"
then I followed it into fopen.c, line 124,
Code:
return( _tfsopen(file, mode, _SH_DENYNO) );
which jumps back up to line 50, the _tfsopen function. After these declarations
Code:
REG1 FILE *stream=NULL;
REG2 FILE *retval=NULL;
retval has all its data, but stream does not. It's got the scary
stream 0x00000000 {_ptr=??? _cnt=??? _base=??? ...} _iobuf *
and all of its data "cannot be evaluated."

Long story short, it successfully completes fopen and all its internal functions even though its now saying "bad pointer" all over the place, then runs
Code:
fseek(file1, 18, SEEK_SET);
and then it breaks in fseek.c on line 100 which is
Code:
_VALIDATE_RETURN( (stream != NULL), EINVAL, -1);
seemingly because stream, which is a FILE* does not have my bitmap file likes it's supposed to. Any suggestions?

I'm running VS2005 with a win32 console app if that makes a difference.

thanks in advance