Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Storing one char array into another


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   -  Reputation: 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;
}


Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 6326

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.



PARTNERS