So I'm trying to replace cc with & in a sentence (eg: "Hi this is Mark cc Alice"). So far I have this code where it replaces the first c with & but the second c is still there. How would I get rid of the second c?
int main() {
char str[] = "Hi this is Mark cc Alice";
int i = 0;
while (str[i] != '\0') {
if (str[i] == 'c' && str[i + 1] == 'c') {
str[i] = '&';
//str[i + 1] = ' ';
}
i++;
}
printf("\n-------------------------------------");
printf("\nString After Replacing 'cc' by '&'");
printf("\n-------------------------------------\n");
printf("%s\n",str);
return str;
}
The input is:
Hi this is Mark cc Alice
The Output is:
Hi this is Mark &c Alice