Jump to content

View more

Image of the Day

I've done more tweaks to my color palette selector. #gamedev #screenshotsaturday #madewithunity https://t.co/aJXrC4ruRg
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Storing one char array into another

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 Captacha   Members   

141
Like
0Likes
Like

Posted 16 January 2012 - 05:07 PM

I am using C++, SDL, and SDL_Image. I am having trouble with an Init() function for loading a .png into a SDL_Surface.I'm trying to load the file variable into the img variable. After that I attempt to load the .png file into my SDL_Surface. There are no syntax errors or warnings, but the file I want doesn't load into the SDL_Surface.
Bomb Bomb::Init(short speed, short radius, short health, char img[25])
{
Bomb Inst;
Inst.alive = true;
Inst.speed = speed;
Inst.radius = radius;
Inst.file[0] = img[0];
Inst.bomb = IMG_Load(file);
Inst.position.y = 300;
Inst.position.x = 400;
Inst.health = health;
return Inst;
}


#2 SimonForsman   Members   

7633
Like
1Likes
Like

Posted 16 January 2012 - 05:20 PM

I am using C++, SDL, and SDL_Image. I am having trouble with an Init() function for loading a .png into a SDL_Surface.I'm trying to load the file variable into the img variable. After that I attempt to load the .png file into my SDL_Surface. There are no syntax errors or warnings, but the file I want doesn't load into the SDL_Surface.

Bomb Bomb::Init(short speed, short radius, short health, char img[25])
{
Bomb Inst;
Inst.alive = true;
Inst.speed = speed;
Inst.radius = radius;
Inst.file[0] = img[0];
Inst.bomb = IMG_Load(file);
Inst.position.y = 300;
Inst.position.x = 400;
Inst.health = health;
return Inst;
}


Inst.file[0] = img[0];


that line copies the first character in img to the first character in Inst.file

after that you try to load file (which really should be Inst.file from the looks of things).

Since you are using C++ you should consider using std::string instead of character arrays.

If you wish to copy a c-style string you need to use the strcpy function.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.