Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-20-2003, 10:06 PM   #1 (permalink)
Pizzaman
Registered User
 
Join Date: Sep 2003
Posts: 8
Pizzaman is on a distinguished road
Unable to get this working!

Hello,

I am trying to load up bitmaps onto DirectX surfaces. Well anyway...

this is the function prototype:

Code:
Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename);
so I tried to read the bitmap names from a file with the following:

Code:
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 initialization
Code:
char 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...

-Pizzaman
Pizzaman is offline   Reply With Quote
Old 09-21-2003, 02:13 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Why initialize tempFile with char tempFilename[256] = {0};?
it's not the value 0 you want to store there, but NULL.

You also might wat to check, that Load_Bitmap_File returns 0(NULL) in case of an error.. I havn't worked with that function so I can't comment on that.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 09-21-2003, 07:26 AM   #3 (permalink)
Dante Shamest
Registered User
 
Dante Shamest's Avatar
 
Join Date: Sep 2003
Posts: 7
Dante Shamest is on a distinguished road
NULL is a macro for 0 in most cases.
Dante Shamest is offline   Reply With Quote
Old 09-21-2003, 10:59 AM   #4 (permalink)
Pizzaman
Registered User
 
Join Date: Sep 2003
Posts: 8
Pizzaman is on a distinguished road
Well I got rid of the initialization {0}.

The function does return(0) in case of error, that's how I caught it. Does it have something to do with infile.getline() not extracting the string properly?

The file is organized:

0 grass1.bmp
1 grass2.bmp
...

Where I get the value first using infile >> value. Then I get the string using infile.getline().

And Load_Bitmap_File is not a standard function, it's by Andre LaMothe, I got it from his book.

-Pizzaman
Pizzaman is offline   Reply With Quote
Old 09-21-2003, 05:55 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
Quote:
Originally posted by Dante Shamest
NULL is a macro for 0 in most cases.
i believe there is a distinct difference between null and 0 in most cases.

0 is an integer value.
__________________
Mike
sde is offline   Reply With Quote
Old 09-21-2003, 06:28 PM   #6 (permalink)
Pizzaman
Registered User
 
Join Date: Sep 2003
Posts: 8
Pizzaman is on a distinguished road
Well thanks guys for the help.

I found my way around it. Instead of having the integer in front of each bitmap name, I just have the bitmap names.

Another forum suggested that there might be an embedded carriage reture. But I checked for that too, and nothing works.

-Pizzaman
Pizzaman is offline   Reply With Quote
Old 09-23-2003, 05:18 PM   #7 (permalink)
npa
Code Monkey
 
Join Date: Jul 2003
Location: canada
Posts: 82
npa is on a distinguished road
Quote:
Originally posted by sde
i believe there is a distinct difference between null and 0 in most cases.
Not in c++ there isn't.
__________________
direct entry file specification.
npa is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
While loop not working alemily PHP 2 06-25-2004 01:07 PM
header not working the way i want it too Imon Fyre PHP 10 02-26-2004 01:46 PM
working with files Miststlkr Standard C, C++ 2 10-13-2003 12:44 PM
cgi script Henry PHP 25 12-30-2002 07:54 AM
cgi not working on a new script sde PHP 3 05-20-2002 09:29 PM


All times are GMT -8. The time now is 02:36 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting