Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Beckie

macrumors newbie
Original poster
Apr 6, 2005
12
0
Hi everyone
I have to getline(cin, string)
Then I have to output the string by separating the words and making them "valid words."

Like for instance I need to change the word To: to the word to
and hat@edu.gov!!! to hat@edu.gov Then I'm supposed to put it into an array.

I think I can do the array part, but I don't know how to output the list of words without the extra characters that don't belong since the list could be an infinite amount of possibilities.

Thanks in advance for the help
Take care,
Beckie
 

DXoverDY

macrumors 6502a
Apr 19, 2005
810
0
Beckie said:
Hi everyone
I have to getline(cin, string)
Then I have to output the string by separating the words and making them "valid words."

Like for instance I need to change the word To: to the word to
and hat@edu.gov!!! to hat@edu.gov Then I'm supposed to put it into an array.

I think I can do the array part, but I don't know how to output the list of words without the extra characters that don't belong since the list could be an infinite amount of possibilities.

Thanks in advance for the help
Take care,
Beckie


ok so you need to remove all invalid characters?

ok.. let's give this a little perspective and see if you can figure it out.

there's a bunch of functions in the ctype.h file..

int isdigit( int c) returns true if c is a digit and false otherwise
int isalpha ( int c ) returns true if c is a letter and false otherwise

since i'm not sure exactly what the correct list of "acceptable" characters is i'll give you a very generic way of doing this.

i'd have 2 strings. 1 with the original, and the other with an altered one you'll be building from scratch.

string 1 ... start with string[0] .. cast as an int.. this will give you an integer .. oddly enough it'll give you the ASCII character number for that letter.

uppercase letters are A-Z starting at 65-90 so 65 = A, 90 = Z
lowercase letters are a-z starting at 97-122 so a = 97, z = 122

so... walk through each character of the string and compare your stuff..

for ( int x = 0; x <= strlen(string); x++ ) {

if ( dynamic_cast< int >(string[x]) >= 65 &&
dynamic_cast< int >(string[x]) <= 90 ||
dynamic_cast< int >(string[x]) >= 97 &&
dynamic_cast< int >(string[x]) <= 122 ) {

do what you need to do to copy the character to your other string

}

}

what this does is remove ALL characters that are not A-Z or a-z

look up the ASCII codes for all others you would want as well and throw them in there.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.