这个C语言程序怎么错了?为什么运行不出来啊。。。

来源:百度知道 编辑:UC知道 时间:2024/06/04 05:51:26
题目是 字符串中只有字母和*。将字符串的前导*全部删除,中间和尾部的*不删除

#include "stdio.h"
void fun(char *a)
{char *p=a,*b;
while((*p=='*')&&(*(++p)=='*'));
while(*p)
{*b=*p;b++;p++;}
*b='\0';}
main()
{char s[81],*t;
gets(s);
t=s;
while(*t) t++;
t--;
while(*t=='*')t--;
fun(s);
printf("the string is:\n");
puts(s);}

谢谢啊

先不说你程序的算法,你的程序有以下问题,在MAIN函数里面T这个指针没有任何意义,你根本没有使用到。FUN函数里面,第一个WHILE你的目的是想把P指向第一个非*的字符,你的P指针已经知道第一个非*字符,那你前导*怎么去掉呢?你的算法再仔细考虑一下吧,我这里给你写了一个。
#include "stdio.h"
main()
{
char s[81],*p;
gets(s);
p=s;
while(*p=='*')p++;
printf("the string is:\n");
puts(p);
}