Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 22nd, 2006, 7:16 PM   #11
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Argh...

The problem is here:
playerRace = {'H', 'u', 'm', 'a', 'n', 0};
When declare an array, you have the option to define it as a whole:
// note: these two do exactly the same thing
char playerRace[] = {'H', 'u', 'm', 'a', 'n', 0};
char playerRace[] = "Human";
This is kind of a favour that the compiler performs for you when compiling. However, at run-time, it won't do that. You have to copy the elements one at a time:
char human[] = "Human";
for (int i = 0; i < 6; i++)
{
	playerRace[i] = human[i];
}

Fortunately, there's a function in the cstring library that does just that for you:
strcpy(playerRace, "Human"); // does the same thing

Of course, you could just pack the whole thing in and use C++ strings instead of C strings:
#include <string>

...

std::string playerRace;

...

playerRace = "Human";
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 22nd, 2006, 7:34 PM   #12
Varrickmana
Newbie
 
Varrickmana's Avatar
 
Join Date: May 2006
Posts: 21
Rep Power: 0 Varrickmana is on a distinguished road
:banana: :banana: :banana: :banana:


YES!!!!!!!!!!
Lol, DaWei, I kept forgetting u said something about strcpy. Your right, I wasn't paying attention!(lol) Thanks to Ooble, it hit me. My game compiles fine now. I learned a lot about C++ and the power of strcpy and it's family with this one thread lol. When I am done with the first version of my game, I will post the source on this site. I can;t tell you guys how thankful I am that u were so patient. Thanks.
__________________
Kids, every year, more than 400,000 people die from tobacco chewing, smoking, an-
MY GOD, HERE COMES A ZOMBIE PIRATE NINJA!!!!!!
Varrickmana is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC