题目描述:设计一个函数将字符串中的字符’‘移动到串的前面部分,前面的非’'字符后移,
但不能改变非’‘字符的先后顺序,函数返回串中字符’'的数量。
如原始串为"abcd***e12",处理后为"*****abcde12",函数返回值为5
将字符串中的字符’'移到串的前部分,保证非字符的顺序位置不能变

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int fun(char array[]) {
int length = strlen(array);
int i, j, count; // count记录*的数目
char temp;

for(i = j = length - 1, count = 0; i >= 0; ) { // 主要是快慢指针的应用 i是快指针,j是慢指针
if(array[i] != '*') {
temp = array[j];
array[j] = array[i];
array[i] = temp;
i--;
j--;
} else {
i--;
count++;
}
}
return count;
}

int main() {

char arr[] = "ab*cd****e12";
printf("*的个数为:%d\n", fun(arr));
puts(arr);

return 0;
}