Why won't this simple thing work?
-
Hello, I am trying to load up bitmaps onto DirectX surfaces. Well anyway... this is the function prototype:
Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);
so I tried to read the bitmap names from a file with the following:infile.open("TileBitmap.dat"); int value = 0; char tempFilename[256] = {0}; while(infile) { infile >> value; //get the bitmap number infile.getline(tempFilename, 256); //get the filename.bmp MessageBox(main_window_handle, tempFilename, "Test", MB_OK); if (!(Load_Bitmap_File(&bit, tempFilename))) { infile.close(); //close the file return 0; //and report error } LoadBitmapSurface(Tiles[value], surface_desc, bit, TILE_WIDTH, TILE_HEIGHT); //if all good, load it into surface array } infile.close();
and the darn thing fails with the Load_Bitmap_File notice the MessageBox function, it outputs the contents of tempFilename. It displays filename.bmp. So it got the name, but it won't load the bitmap. So I tried... manual initializationchar tempFilename[256] = "filename.bmp" Load_Bitmap_File(&bit, tempFilename);
and that works fine! So what could be the problem here? is it somethhing with the cin.getline?? I checked the length, and it was correct... Please help thanks! -Pizzaman -It's like blowing up an abortion center because you are pro life. -
Hello, I am trying to load up bitmaps onto DirectX surfaces. Well anyway... this is the function prototype:
Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);
so I tried to read the bitmap names from a file with the following:infile.open("TileBitmap.dat"); int value = 0; char tempFilename[256] = {0}; while(infile) { infile >> value; //get the bitmap number infile.getline(tempFilename, 256); //get the filename.bmp MessageBox(main_window_handle, tempFilename, "Test", MB_OK); if (!(Load_Bitmap_File(&bit, tempFilename))) { infile.close(); //close the file return 0; //and report error } LoadBitmapSurface(Tiles[value], surface_desc, bit, TILE_WIDTH, TILE_HEIGHT); //if all good, load it into surface array } infile.close();
and the darn thing fails with the Load_Bitmap_File notice the MessageBox function, it outputs the contents of tempFilename. It displays filename.bmp. So it got the name, but it won't load the bitmap. So I tried... manual initializationchar tempFilename[256] = "filename.bmp" Load_Bitmap_File(&bit, tempFilename);
and that works fine! So what could be the problem here? is it somethhing with the cin.getline?? I checked the length, and it was correct... Please help thanks! -Pizzaman -It's like blowing up an abortion center because you are pro life.Is it possible that
tempFilename
contains an embedded LF or CRLF at the end of the string? That would explain why it would display fine in the message box, but would still bomb out. Stepping through in a debugger would be advised :) - Mike -
Is it possible that
tempFilename
contains an embedded LF or CRLF at the end of the string? That would explain why it would display fine in the message box, but would still bomb out. Stepping through in a debugger would be advised :) - Mike -
Hello, I am trying to load up bitmaps onto DirectX surfaces. Well anyway... this is the function prototype:
Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);
so I tried to read the bitmap names from a file with the following:infile.open("TileBitmap.dat"); int value = 0; char tempFilename[256] = {0}; while(infile) { infile >> value; //get the bitmap number infile.getline(tempFilename, 256); //get the filename.bmp MessageBox(main_window_handle, tempFilename, "Test", MB_OK); if (!(Load_Bitmap_File(&bit, tempFilename))) { infile.close(); //close the file return 0; //and report error } LoadBitmapSurface(Tiles[value], surface_desc, bit, TILE_WIDTH, TILE_HEIGHT); //if all good, load it into surface array } infile.close();
and the darn thing fails with the Load_Bitmap_File notice the MessageBox function, it outputs the contents of tempFilename. It displays filename.bmp. So it got the name, but it won't load the bitmap. So I tried... manual initializationchar tempFilename[256] = "filename.bmp" Load_Bitmap_File(&bit, tempFilename);
and that works fine! So what could be the problem here? is it somethhing with the cin.getline?? I checked the length, and it was correct... Please help thanks! -Pizzaman -It's like blowing up an abortion center because you are pro life.When using
infile.getline(tempFilename, 256);
, could there be extra (hidden) characters intempFilename
?MessageBox()
is not exactly the best choice to use for looking at data. Using both methods you described, put a breakpint on theLoad_Bitmap_File()
line and look attempFilename
in the debugger at that point. See if there are any differences between the two.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?