回复 13楼 是2014
指针有些地方用得不合理,修改了一下:
#include <stdio.h>
void fun(char *a, char *p)
{
char *aa=a;
char m[81]= {'0'};
char *q=m;
//int j=0;
while(a<p)
{
if(*a!='*')
*q++=*a;
a++;
}
while(*a)
{
*q++=*a;
a++;
}
*q='\0';
q=m;
while(*q)
*aa++=*q++;
*aa='\0';
}
main()
{
char s[81],*t;
//void NONO ();
printf("Enter a string:\n");
gets(s);
t=s;
while(*t)t++;
t--;
while(*t=='*')t--;
fun(s , t);
printf("The string after deleted:\n");
puts(s);
//NONO();
}
化简些的话可以这样:
#include <stdio.h>
char *fun(char *s)
{
char *p1, *p2;
for (p1=p2=s; *p1; p1++)
if (*p1 != '*')
*p2++ = *p1;
for(--p1; *p1=='*' && p1>=s; p1--)
*p2++ = *p1;
*p2 = 0;
return s;
}
main()
{
char s[81];
printf("Enter a string:\n");
gets(s);
fun(s);
printf("The string after deleted:\n");
puts(s);
}
[此贴子已经被作者于2017-3-21 14:41编辑过]