Jump to content
  • Advertisement
Sign in to follow this  
captacha

Storing one char array into another

This topic is 2529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using C++, SDL, and SDL_Image. I am having trouble with an [font=courier new,courier,monospace]Init()[font=comic sans ms,cursive] [font=arial,helvetica,sans-serif]function for loading a [font=courier new,courier,monospace].png[font=arial,helvetica,sans-serif] into a [font=courier new,courier,monospace]SDL_Surface[font=arial,helvetica,sans-serif].[/font][/font][/font][/font][/font][/font][/font][font=courier new,courier,monospace][font=comic sans ms,cursive][font=arial,helvetica,sans-serif][font=courier new,courier,monospace][font=arial,helvetica,sans-serif][font=courier new,courier,monospace][font=arial,helvetica,sans-serif]I'm trying to load the [font=courier new,courier,monospace]file[/font] variable into the [font=courier new,courier,monospace]img [font=arial,helvetica,sans-serif]variable. After that I attempt to load the [font=courier new,courier,monospace].png[font=arial,helvetica,sans-serif] file into my [font=courier new,courier,monospace]SDL_Surface[font=arial,helvetica,sans-serif]. There are no syntax errors or warnings, but the file I want doesn't load into the [font=courier new,courier,monospace]SDL_Surface.[/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font]

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

Share this post


Link to post
Share on other sites
Advertisement

I am using C++, SDL, and SDL_Image. I am having trouble with an [font=courier new,courier,monospace]Init()[font=comic sans ms,cursive] [font=arial,helvetica,sans-serif]function for loading a [font=courier new,courier,monospace].png[font=arial,helvetica,sans-serif] into a [font=courier new,courier,monospace]SDL_Surface[font=arial,helvetica,sans-serif].[/font][/font][/font][/font][/font][/font][/font][font=courier new,courier,monospace][font=comic sans ms,cursive][font=arial,helvetica,sans-serif][font=courier new,courier,monospace][font=arial,helvetica,sans-serif][font=courier new,courier,monospace][font=arial,helvetica,sans-serif]I'm trying to load the [font=courier new,courier,monospace]file[/font] variable into the [font=courier new,courier,monospace]img [font=arial,helvetica,sans-serif]variable. After that I attempt to load the [font=courier new,courier,monospace].png[font=arial,helvetica,sans-serif] file into my [font=courier new,courier,monospace]SDL_Surface[font=arial,helvetica,sans-serif]. There are no syntax errors or warnings, but the file I want doesn't load into the [font=courier new,courier,monospace]SDL_Surface.[/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font][/font]

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!