Well right now this code Removes one specific letter from the string we give.
The problem is that i found this func code on google so i don't really understand it(I am very new to this)
I made the main's code myself.
1)I need some help to understand what
Code:
string str = phrase;
do???
2)Why when i put
Code:
cout << str << endl;
in main give me some random numbers??even if i change str with z, give me some other random numbers...
3)THIS IS THE MOST IMPORTANT even if u can't help with others.
I need to add in this code something that removes multiple spaces and leaves only ONE space.
This program in the end should
Take a String(Phrase) as an Input and a Letter to remove
Remove Multiple Spaces and leave only 1 space between each word
and give as the String(Phrase) with the specific letter removed and with only 1 space between each word.
EXAMPLE:
"What___a__great_____________weather__we have today" (consider underscore as a space because the forum doesn't let u put multiple spaces)
and lets say we want to remove "e"
SHOULD BECOME:
"What a grat wathr w hav"
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int func(int i,char phrase[80]){
string str = phrase;
char remove = i;
for(string::iterator it = str.begin(); it!=str.end(); ){
if( (*it) == remove )
it = str.erase( it );
else
it++;
}
cout << str << endl;
}
int main(int argc, char *argv[])
{
int i, n, z;
char phrase[80];
printf("\nGive a Phrase ");
gets(phrase);
printf("\nThe Phrase is: "" %s\n"" ",phrase);
printf("\nGive the letter you want to be removed ");
scanf("%c",&i);
z=func(i,phrase);
system("PAUSE");
return EXIT_SUCCESS;
}