Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Annoying strcpy problem

Status
Not open for further replies.

The

Programmer
Jul 30, 2001
92
CA
I'm making a program, and I have a class called "Cell". Two members of this class are:

char dChar;
char hChar;

In the constructor, I have dChar set to "?", and I try to have hChar set to "X". However, when I go to output both of these values, only the dChar shows up. I did strcpy to both of them, with no variations. I'm fairly new to C++, so I'm wondering if, for some reason, you can only have one char variable in a class. I don't see why that would be, but it's the only explanation I can think of. Can anyone help? Thanks.
 
Your char variables (dChar and hChar) can only hold one (1) character.

You shouldn't use strcpy() to initialize these variables, since strcpy will add a terminating zero - i.e. 2 characters will be needed to hold the result.

/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top