https://blog.csdn.net/dangzhangjing97/article/details/83956567
bool replace(char *a, int size) {
if(a == NULL || 0 == size) {
return false;
}
int numBlank = 0;
int i = 0;
while (a[i] != '\0') {
i++;
if(a[i] == ' ') {
numBlank++;
}
}
int curLen = i;
if(curLen + numBlank*2 > size) {
return false;
}
int curPos = curLen-1;
int newPos = curLen + numBlank*2 - 1;
while (newPos > curPos) {
if(a[curPos] == ' ') {
a[newPos--] = '%';
a[newPos--] = '0';
a[newPos--] = '2';
}
else {
a[newPos] = a[curPos];
newPos--;
}
curPos--;
}
return true;
}
char arr[30] = "we are like study . ";
bool rep1 = replace(arr,30);