By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

Accessing characters in character array

P: n/a
I am writing a c++ program for one of my classes. One of the assignments I
had was to create a program that would bascially calculate the number of
points in a game of Bridge using the principles of Object orientied
programming. The input is a stream of characters which represent the value
and suit of the card. For example, as would represent ace of spades, 2d
would be two of diamonds etc. To handle that I have created four arrays of
thirteen(since a suit can't have more than 13 values) characters , called
ClubArray, DiamondArray, HeartArray, and SpadesArray to store the different
values of a particulier suit. In the program I have to not only display the
points but also display the cards of a particulier hand by suit. To make
this more clear the output would look something like this:

Clubs: 10 6 2
Diamonds: A Q 10 3
Hearts: K J 7 5 3
Spades: A
Points = 16

To print out the values by rank I have used this while loop sequence:
cout<<"Clubs: ";
while(ClubArray[i] != '\0'){
cin<<ClubArray[i]<<" ";
All the values have been initialized to the NULL character('\0'), so the way
the loop works it would display any character that is not the null character
where it would break out of the loop since there are no values to be stored.
The problem that occurs though is that that line of code not only displays
the character that at ClubArray[i] but all the characters that follow as if
it was a string!

I have tried several other output schemes like put(ch), cin.put<<etc,
putchar(ch) but to no avail. Can anyone help me?

I would really appreciate it.

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
"Gregory W. Ernest" <Ge*****> wrote in message


If you want to post a message to more than one group,
don't post separate messages, crosspost instead (put
both group names in the 'newsgroup' field). This way
when folks read in one group, the newsreaders will
show it also read in the other(s).

See my reply I posted to your message
in group 'alt.comp.lang.learn.c-c++'

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.