所以我试图cc用&一个句子替换(例如:)"Hi this is Mark cc Alice"。到目前为止,我有这个代码,它替换了第一个c,&但第二个c仍然存在。我将如何摆脱第二个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;
}
Run Code Online (Sandbox Code Playgroud)
输入是:
Hi this is …Run Code Online (Sandbox Code Playgroud)