473,789 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing characters in character array

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]<<" ";
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[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
1 1255
"Gregory W. Ernest" <Ge*****@optonl ine.net> wrote in message
news:3o******** ***********@fe0 9.lga...

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
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
3795
by: Vladimir | last post by:
Method UnicodeEncoding.GetMaxByteCount(charCount) returns charCount * 2. Method UTF8Encoding.GetMaxByteCount(charCount) returns charCount * 4. But why that? Look: /* Each Unicode character in a string is defined by a Unicode scalar value, also called ...
14
42432
by: deko | last post by:
Is there a way to check user input for illegal characters? For example, a user enters something into a text box and clicks OK. At that point I'd like to run code such as this: illegal = Array(\, /, :, *, ?, ", <, >, |) If Me.TextBox Contains illegal Then MsgBox "You entered illegal characters. Please try again." Me.TextBox = Null
35
2554
by: Durgesh Sharma | last post by:
I want to use strrchar(source_string,last_char ) function from string.h header file,to find out the last occurrence of the NON SPACE Alphanumeric Character. Then i will put a NULL CHAR after incrementing that position,received by strrchar() function by 1. This is my idea of Trimming a string from right . According to the definition of the strrchar function,i am supposed to
8
1871
by: Dawn Minnis | last post by:
Hey guys If I have a program (see codeSnippet1) that I compile to be called test.o Then run it as test.o n n 2 3 4 I want the code to be able to strip out the two characters at the start (always going to be 2) and store them as characters. But I can't seem to get it to work because it is a pointer to a vector of characters. However, if I only run with integer arguements and use codeSnippet2 it works fine and they convert nicely to...
89
6083
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
1
1468
by: Peter Robinson | last post by:
Dear list I am at my wits end on what seemed a very simple task: I have some greek text, nicely encoded in utf8, going in and out of a xml database, being passed over and beautifully displayed on the web. For example: the most common greek word of all 'kai' (or καιif your mailer can see utf8) So all I want to do is: step through this string a character at a time, and do something for each character (actually set a width...
16
6800
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
14
13545
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h>
13
3931
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type Chinese characters, but neverthelss is unable to show them up on screen. The follow is some of the error message I received after I logged off the program: "Could not write output: <type "exceptions: UnicodeEncodeError'>, 'ascii' codec can't...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10412
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3703
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.