-
April 5th, 2012, 12:56 PM
#1
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";
}
-
April 5th, 2012, 01:00 PM
#2
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.
-
April 5th, 2012, 01:19 PM
#3
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 ?
-
April 5th, 2012, 01:23 PM
#4
Re: help please
Originally Posted by emmalola
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|