Posted: Tue May 30, 2006 8:17 am Post subject: names and char arrays
hey guys im making a game for my summative in programming. i need the player to choose a player class using numbers ( example: 1 = fighter,2=mage , etc) but then in my if statement, my character array to say the class name will not say the name. is says " incompatible types in assignment of `const char[8]' to `char[20]'"
i set the char array to 20 because my largest class needs 20 spaces, but the others range from 4 to 12.
How can i get the array to see that, whether or not the array is full, to fill the array to the maximum for the player class size and then fill the rest woth blanks?
Sponsor Sponsor
md
Posted: Tue May 30, 2006 10:55 am Post subject: (No subject)
you are trying to copy arrays; which doesn't work. You'd need to use the string functions to copy from one buffer to the other (see string.h)
If this is C++ I'd recomend using the std::string class instead as it will keep you from having to deal with character arrays (which are really really prone to overflow and memory leaks). <string> and <stdio> are your friends
wtd
Posted: Tue May 30, 2006 11:05 am Post subject: (No subject)
Cornflake wrote:
If this is C++ I'd recomend using the std::string class instead as it will keep you from having to deal with character arrays (which are really really prone to overflow and memory leaks). <string> and <stdio> are your friends
If you want to use "stdio.h" in C++, then you want to include "cstdio".
md
Posted: Tue May 30, 2006 12:28 pm Post subject: (No subject)
I was actually thinking more along the lines of <iostream> but what with it being early and all I wasn't quite thinking.
flameZero
Posted: Wed May 31, 2006 7:20 am Post subject: (No subject)