943,937 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1460
  • C++ RSS
Feb 4th, 2006
0

Strings

Expand Post »
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 .
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nickol is offline Offline
3 posts
since Feb 2006
Feb 4th, 2006
2

Re: Strings

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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Feb 4th, 2006
0

Re: Strings

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;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nickol is offline Offline
3 posts
since Feb 2006
Feb 4th, 2006
0

Re: Strings

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).
Reputation Points: 185
Solved Threads: 28
Posting Whiz in Training
dwks is offline Offline
269 posts
since Nov 2005
Feb 4th, 2006
0

Re: Strings

Try something like this....
C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 11
Solved Threads: 0
Light Poster
Nedals is offline Offline
43 posts
since Dec 2005
Feb 5th, 2006
0

Re: Strings

Thank you ,
Appriciated .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nickol is offline Offline
3 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: What am I doing wrong?
Next Thread in C++ Forum Timeline: System()





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC