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 .

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.

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;
}

Use [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).

Try something like this....

<<sudocode>>
first = true;
In a for loop, using the char array...
  if (first) {
    build a string of chars in 'temp1' until there is a space
    and set first = false;
  }
  then build a string in 'temp2' until space.
  now compare temp1 to temp2. If they match, print temp1
  copy temp2 into temp1
  repeat
}

Thank you ,
Appriciated .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.