help please
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: help please

  1. #1
    Join Date
    Feb 2012
    Posts
    7

    help please

    hi , i have to write a programme that deletes successive duplicate letters , for example : it's hooooot has to become it's hot
    that"s what i've done but it doesn't really work , can you help me fix that . thank you

    //Programme qui efface les caractères identiques successifs
    #include "stdafx.h"
    #include <cstring>
    #include <iostream>
    using namespace std;
    void transformer();
    char *saisir();
    int const i = 80;
    char phrase[i];
    char *phraseptr = phrase;

    int _tmain(int argc, _TCHAR * argv[])
    {
    saisir();
    transformer();
    return 0;
    }

    char *saisir()
    {
    cout << "Veuillez taper une phrase:"<< endl; // Demander à l'utilisateur de saisir une phrase ou un mot
    cout << "nn";
    gets(phrase);
    return phraseptr;
    }

    void transformer()
    {
    for (int x = 0; x < 80; x++)
    if (phrase[x] == phrase[x + 1]);
    cout << "n";
    cout << "Voici votre phrase modifiée:"; // Affiche la phrase modifiée en eliminant les répétitions de caracteres s'il y'a lieu
    cout << "nn";
    cout << phrase;
    cout << "nn";
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,049

    Re: help please

    This is probably a problem
    Code:
    if (phrase[x] == phrase[x + 1]);
    I'm surprised your compiler didn't warn you.

    Also, you don't want to loop 80 times. Just loop till the end of your phrase.

    The rest of your logic doesn't seem to make any sense given the goal.

  3. #3
    Join Date
    Feb 2012
    Posts
    7

    Re: help please

    but i have to state a constant in the main function equal to 20 , so i have to loop 20 times . but i don't understand how i can write this programe can u help me ?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,049

    Re: help please

    Quote Originally Posted by emmalola View Post
    but i have to state a constant in the main function equal to 20 , so i have to loop 20 times . but i don't understand how i can write this programe can u help me ?
    Why do you need a constant equal to 20? The one you defined is 80. Either way, looping past the end of the phrase is pointless.

    I can help you, but you need to understand the steps in your head before you try to write code. While there are several ways to do it, if it were me, I'd probably copy the characters from one array to another, one character at a time, but I'd skip characters that were equal to the last one I copied.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center