I am trying to return the index of the element containing character 'r' which has charcater 'u' as its successor. The following piece of code always returns the varialbe ruindex =0. Please suggest edits in the code.
int ruindex=0;
if (s1[0]=='h') {
s2[0] = 'h';
s2[1] = 't';
s2[2] = 't';
s2[3] = 'p';
s2[4] = ':';
s2[5] = '/';
s2[6] = '/';
for (int i=4; i < s1.length-1; i++) {
if (s1[i]=='r' && s1[i+1]=='u') {
ruindex = i;
break;
}
}
}
It is just a part of my overall code. Yes there is a reason why I want to start from i=4. What I wish to do is that whenever I encounter 'r' and 'u' together in the character array, I want to return the index of that 'r'.
i=4, you're only setting ups2if the first value ofs1ish, there isn't thisrins2you're looking for and what doess1ands2mean here, why are there 2 separate variables? Please elaborate on your requirements and provide an SSCCE.s1