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?
How do you check if a spot in a char array has a character there or not (C++)?
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.
Reply:look up isalpha
something like
if (!isalpha(int(temp[count])) notChar = true;
can't recall what header file.
garden design
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment