Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 names and char arrays
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
flameZero




PostPosted: 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
Sponsor
sponsor
md




PostPosted: 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 Wink
wtd




PostPosted: 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 Wink


If you want to use "stdio.h" in C++, then you want to include "cstdio". Smile
md




PostPosted: 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




PostPosted: Wed May 31, 2006 7:20 am   Post subject: (No subject)

ok thanks alot for the help Very Happy
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: