I've received a task, where I have to change every 5th character of a character array to =
character and then shift the other elements of the array right, like this: I like fruit
--> I lik=e fru=it
.
I have trouble with how to shift the elements after the =
characters. I was considering something similar to simple sorting, but I just can't imagine how to switch and which elements. Could you help me out, please? Thanks in advance!
I could complete the code this far:
#include<cstring>
#include<fstream>
int main(){
char sentence[] = "I like fruit";
int length = strlen(sentence);
for(int i = 1; i < length; i++){
if(i % 5 == 0){
sentence[i] = '=';
}
}
std::cout << sentence << '\n';
return 0;
}