Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 1, 2005, 06:06 PM   #1
Beckie
macrumors newbie
 
Join Date: Apr 2005
Question about taking off parts of a word

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
Beckie is offline   0 Reply With Quote
Old May 1, 2005, 11:16 PM   #2
DXoverDY
macrumors 6502a
 
Join Date: Apr 2005
Quote:
Originally Posted by Beckie
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.

Last edited by DXoverDY; May 1, 2005 at 11:28 PM.
DXoverDY is offline   0 Reply With Quote
Old May 2, 2005, 02:03 AM   #3
Beckie
Thread Starter
macrumors newbie
 
Join Date: Apr 2005
Thank you so much for your help!
Take care,
Beckie
Beckie is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
fcp export cuts off part of video Monduras Digital Video 5 Jun 20, 2010 05:10 PM
questions about taking over a car lease...? chstr Community Discussion 1 Mar 19, 2010 07:10 PM
Question about customer upgrade parts and apple care. zsnow MacBook Pro 7 Jun 23, 2009 11:31 PM
question about lay offs in NYC andiwm2003 Community Discussion 0 Apr 1, 2008 09:00 PM
Question re: calendars as part of the wallpaper. JonHimself OS X 3 Mar 19, 2006 07:05 PM


All times are GMT -5. The time now is 02:02 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC