#include <stdio.h> void fun(char str[]){ char *p1,*p2,*p3; p1 = str; p2=str; p3=str; while(*p3) p3++; p3--; while(*p1=='*') p1++; while(*p3=='*') p3--; p2=p1; while(p2<p3){ if(*p2=='*') { p2++; continue; } else *p1++=*p2++; } while(*p2) *p1++=*p2++; } int main(){ char str[100] = "***A*BC*DEF*G******"; fun(str); printf("%s",str); }
注意两个条件不能同时用++,要不然会实现两次++