English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm having problems couting a character array. It couts the list of characters, plus a bunch of junk after it. So then I need to set up a while statement...

bool notChar = false;
int count = 0;
while(notChar = false) {
cout temp[count];
count++;
if(temp[count] == ???) { notChar = true; }
}

...Any ideas?

2006-11-17 09:16:59 · 2 answers · asked by Harb Frame 3 in Computers & Internet Programming & Design

2 answers

char* or char[ ] types typically use a char value of 0 to mark the end of the string.

however, "cout" will stop at this 0 automatically, so you obviously do not have a 0 at the end of the string.

the best bet would be to not use a char* or char[ ] type at all, but use a STL::string type. research the C++ standard tempalte libraries. it has a string type with everything built in.

if you must use char* or char[ ], initialize your array to all 0's and never use the final size'd spot. this is clumsy C programming though, not C++. Use the STL in C++, it prevents many bugs.

2006-11-17 10:29:30 · answer #1 · answered by WickedSmaht 3 · 0 0

look up isalpha

something like

if (!isalpha(int(temp[count])) notChar = true;

can't recall what header file.

2006-11-17 19:04:34 · answer #2 · answered by Arkane Steelblade 4 · 0 0

fedest.com, questions and answers