主题:[讨论]请人帮我分析一道题!
jojpst007
[专家分:0] 发布于 2010-09-04 23:52:00
[size=4][color=0000FF]请详细分析一下fun函数里的每条语句,谢谢!!![/color][/size]
#include <stdio.h>
#include <conio.h>
void fun(char *a,int n)
{
int i=0,k=0;
char *p,*t;
p=t=a;
while(*t)
{
t++;
}
t--;
while(*t=='*')
{
k++;
t--;
}
t++;
if (k>n)
{
while(*p&&p<t+n)
{
a[i] = *p;
i++;
p++;
}
a[i] = '\0';
}
}
void main()
{
char s[81];
int n;
printf("Enter a string :\n");
gets(s);//abc***
printf("Enter n: ");
scanf("%d",&n);//2
fun( s,n );
printf("The string after deleted :\n");
puts(s);
}
沙发
香蕉枪打星爷 [专家分:50] 发布于 2010-09-05 09:42:00
void??fun(char??*a,int??n) { ????????int??i=0,k=0; 定义并赋值变量????????char??*p,*t;定义字符指针变量 ????????p=t=a;把a的指针变量的地址赋值给 t,t再把地址赋值给p指针????????while(*t)当条件为真的就执行下面花括号的语句 ????????{ ????????????t ;自加 ????????} ????????t--;自减 ????????while(*t=='*')为真就执行下面花括号语句 ????????{ ????????????????k ;自加 ????????????????t--; 自减????????} ????????t ;自加 ??????if??(k>n)条件为真就执行下面的语句 ??????{ ????????????????while(*p&&p<t n)为真就执行任务下面的语句 ????????????????{ ????????????????????????a[i]??=??*p;把指针所指地址的值,赋植给数组元素a[i] ????????????????????????i ;自加 ????????????????????????p ;自加 ????????????????} ????????????????a[i]??=??'\0';元素不等于空操作字符 ????????} }