2 or more

closed account (4w7X92yv)
Hello

I got this code witch seperates a piece of the inputted data string and ignores a part (in this case 'f').
How can i do it so it checks if the code contains f and the following is also f
like ff

this is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{ 

std::string code;
getline(cin,code);

std::string test;

unsigned int offset = 0;
unsigned int count = 0;

while((count < 8) && (offset < code.size())){
if(code[offset] != 'f'){
test.push_back(code[offset]);
count = count + 1;
}
offset = offset + 1;
}

std::cout << test << std::endl;

system ("pause");
return 0;
}


this is what the output is:
1
2
abcdefghijklmnopqrstuvwxz
abcdeghi


if the output also does:
1
2
jmfjmffpiougr
jmjmpoug


what the output should do:
1
2
jmfjmffpiougr
jmfjmpio


it should check if 2 or more f are one after the other.

how can i make that happen?

Best Regards
Joriek
closed account (4w7X92yv)
help
Change while((count < 8) && (offset < code.size())) to just while(offset < code.size()), and get rid of the count variable. Not really need with this version. It ran beautifully for me.

Change if(code[offset] != 'f') to if(code[offset] != 'f' && code[offset] != 'F') if you want it to check for capital 'F's, also.
Last edited on
closed account (4w7X92yv)
Indeed but it should only ignore multiple 'f' like 'ff' or 'ffffff'. When the only 1 'f' is detected it should leave it there.

how to do that?
@joriek..

Sorry, I tried different ways, and was also unable to figure it out. Hopefully, someone more knowledgeable, will be able to help out.
closed account (4w7X92yv)
:( thanks anyway

anyone else has an idea?
You question is a bit unclear.

Are you wanting to strip out all repeated 'f' chars, but leave all the other chars?

jmfjmffpiougr --> jmfjmpiougr
offoffk --> ook
etc
Last edited on
Topic archived. No new replies allowed.