Strings

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2006
Posts: 3
Reputation: Nickol is an unknown quantity at this point 
Solved Threads: 0
Nickol Nickol is offline Offline
Newbie Poster

Strings

 
0
  #1
Feb 4th, 2006
Hey,
I have to write a function that does this :
It checks if a word come up twice in a row .
For example :
myString[] = " Ariel lives in in the city city Ariel "

so now my function should print the words : in city .
because they are words that appear twice , notice that Ariel should not be printed because the word Ariel doesn't appear 1 after another.

pls help me solve this .
Thanks ahead ,
Nickol .
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Strings

 
0
  #2
Feb 4th, 2006
No.

If you don't solve this problem yourself, you won't be solve the problem that comes after this one, or the problem that comes after that. You'll might be able to squeak by with a passing grade, but you'll have learned nothing.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 3
Reputation: Nickol is an unknown quantity at this point 
Solved Threads: 0
Nickol Nickol is offline Offline
Newbie Poster

Re: Strings

 
0
  #3
Feb 4th, 2006
I'm trying for 2 days to do so ..
But i'm so confused by the loops that i created .
Here's what i was trying to do :

const int SIZE=35;
int main()
{
int Length;
int counter=0;
char secString[SIZE];
char myString[SIZE] = "Ariel is in in the city city Ariel";
cout<<myString<<endl;

Length = strlen(myString);
cout<<"Length of the String is :"<<Length<<endl;

for (int i=0;i<Length;i++)
{
if (myString[i] == ' ')
for (int j=i;j>=0;j--)
{
secString[j] = myString[j];
cout<<"secString is : "<<secString<<endl;
}
counter++;
}
cout<<"You have "<<counter<<" Spaces in your String"<<endl;
cout<<"secString is : "<<secString<<endl;
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Strings

 
0
  #4
Feb 4th, 2006
Use [code] [/code] tags.

You can use C++-style strings and the find() function. Or you can use strstr(). Or you can stick with for loops.

Hint: ignore chars until you reach a space (or until isspace() (in <ctype.h>/<cctype>) returns non-zero).
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 43
Reputation: Nedals is an unknown quantity at this point 
Solved Threads: 0
Nedals Nedals is offline Offline
Light Poster

Re: Strings

 
0
  #5
Feb 4th, 2006
Try something like this....
  1. <<sudocode>>
  2. first = true;
  3. In a for loop, using the char array...
  4. if (first) {
  5. build a string of chars in 'temp1' until there is a space
  6. and set first = false;
  7. }
  8. then build a string in 'temp2' until space.
  9. now compare temp1 to temp2. If they match, print temp1
  10. copy temp2 into temp1
  11. repeat
  12. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 3
Reputation: Nickol is an unknown quantity at this point 
Solved Threads: 0
Nickol Nickol is offline Offline
Newbie Poster

Re: Strings

 
0
  #6
Feb 5th, 2006
Thank you ,
Appriciated .
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC