用C语言 删除前置和后置的“*”

来源:百度知道 编辑:UC知道 时间:2024/05/02 18:51:55
有一题这样的程序,是用来删除前置的“*”
char *del (char *q)
{ char *s=q;
while(*q= =‘*’)
{q++;s++;}
return s; }
main()
{char str[80],*p;
printf(“input a string :\n”);
scanf(“%s”,str);
p=del(str);
printf(“%s\n”,p);
}

要求在原基础上补充这个程序,使它也能删除后置的“*”
只能用#include <stdio.h>和#include <string.h>两个库函数 把前置和后置写分开

VC6运行通过.
自己试一下.

---------------------------
#include <stdio.h>
#include <string.h>
int len;
char *delbefore (char *q)
{
char *s=q;
while(*q=='*')
{q++;s++;}
return s;
}

char *delend (char *q)
{
char *s=q;
while(*(q+len-1)=='*')
{*(q+len-1)='\0';q--;}
return s;
}

void main()
{
char str[80],*p;
printf("input a string :\n");
scanf("%s",str);
p=delbefore(str);
len=strlen(p);
p=delend(p);
printf("%s\n",p);
}

传入的字符串是什么格式的?想要得到什么结果?

给一个例子嘛!真是的!