成绩: 100 / 折扣: 0.8
假定输入的字符串中只包含字母和 * 号。请编写函数 fun ,它的功能是:除了尾部的 * 号之外 , 将字符串中其它 * 号全部删除。在编写函数时,不得使用 C 语言提供的字符串函数。
例如,字符串中的内容为: ****A*BC*DEF*G******* ,删除后 , 字符串中的内容应当是: ABCDEFG******* 。
#include <stdio.h>
*********************
补全中间的代码
*********************
int main()
{ char s[81],*t;
gets(s);
t=s;
while(*t) t++;
t--;
while(*t=='*') t--;
fun( s , t );
puts(s);
return 0;
}
#include<stdio.h>
int main()
{
char s[100],*p ,*q ;
puts("输入小于100个字符:");
gets(s);
for(p=s,q=s;*p!='\0';p++)
if(*p!='*')*q++=*p;
*q=*p;
puts(s);
return 0;
}
运行结果
我弄明白了
void fun( char *a, char *p )
{
char *q=a;
int j=0;
while(*q && q<p)
{
if(*q != '*') a[j++] = *q ;
q++ ;
}
while(*p) a[j++]=*p++;
a[j]=0;
}