Accessing characters in character array

  • Thread starter Gregory W. Ernest
  • Start date
G

Gregory W. Ernest

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 != '\0'){
cin<<ClubArray<<" ";
i++;
}
cout<<endl;
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 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.
 
M

Mike Wahler

Gregory:

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++'

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,650
Latest member
IanTylor5

Latest Threads

Top