一个c语言字符串小程序!
一个c语言小程序: 将字符串中间的*号移动到最后。输入字符串: ***A**B***CD**
输出字符串: ***ABCD*******
#include<stdio.h>
int strlength(char *a) {
int length = 0;
while((*a) != '\0') {
length ++;
a++ ;
}
return length;
}
void fun(char *a)
{
/****A*B**C***/
int strlen = strlength(a);
char *p;
p = a;
int index = 0;
while((*p) == '*') {
p++;
index ++;
}
int leftLength = strlen - index;
int i = 0;
int repeat = 0;
while(i<(leftLength-1)) {
p = a + index + i;
if((*p) == '*') {
for(int j=i+index;j<strlen-1;j++) {
a[j] = a[j+1];
}
a[strlen-1] = '*';
i--;
repeat ++;
if(repeat==100) break;
}
i++;
}
}
void main()
{
char s[81],*p;int n=0;
printf("Enter a string:\n");
gets(s);
printf("接收ok!");
fun(s);
printf("The string after moveing:\n");
puts(s);
}