Storing one char array into another

Started by
0 comments, last by SimonForsman 12 years, 3 months ago
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;
}
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.
[size="1"]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!

This topic is closed to new replies.

Advertisement