copying one chartor at a time

Hi, I want to copy "hello" letter by letter but when it hits e i want to skip it so that it prints "hllo"..I have used the following code but when it gets to e the rest of the letters don't show up. just prints the first letter with is the h...how can i make this work..thanks


char enterletters[]="hello";
char shi[]="e";
char copy_letter[50];
for (int ff=0; ff<5; ff++)
{
if (enterletters[ff]==shl[0])
++ff;

copy_letter[ff]=enterletters[ff];

}
cout <<copy_letter<<endl;
Replace ++ff; with continue;, and make sure to initialize copy_letter with all zeros, or copy the null terminator from enterletters:

char copy_letter[50] {};

Alternatively, do something like this:

1
2
3
4
5
6
7
8
9
10
# include <iostream>
# include <iterator>
# include <algorithm>

int main() {
    static std::string const skip {"efg"}; // skip the characters appearing in this string
    std::copy_if(std::istream_iterator<char>{std::cin}, {}, 
                 std::ostream_iterator<char>{std::cout}, 
                 [](char const c) { return skip.find(c) == std::string::npos; } );
}

Demo:
http://coliru.stacked-crooked.com/a/2fb342d81ef56510
Last edited on
how do i make it so the "cin" is the variable and the "cout" would be the variable output, and it goes on to the next line. instead ot it repeating itself. also I would like were the letters to be a variable, also and I wanted only to have one letter removed so if the variable holds two 'ee' i only want one to be removed. thanks

Last edited on
Topic archived. No new replies allowed.