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;
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";
}
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 ?
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.
Bookmarks