指针作为函数参数时程序没有修改指针
intcreat(structsoldier*s_head,intc,intm){structsoldier*s_p,*s_q;inti=1,j=c,k=0;s_head...
int creat(struct soldier *s_head,int c,int m)
{
struct soldier *s_p,*s_q;
int i=1,j=c,k=0;
s_head=s_p=s_q=0;
for(;i<=c;i++)
{
s_p=(struct soldier *)malloc(sizeof(struct soldier));
s_p->number=i;
s_p->flag=0;
s_p->id=i;
if(s_head==NULL)
s_head=s_p;
else
s_q->next=s_p;
s_q=s_p;
}
s_p=s_head;
while(j>=m)
{
s_p=s_head;
k=1;
while(s_p)
{
if(s_p->flag==0)
{
if(s_p->number%m==0)
{
s_p->number=k++;
}
else
{
s_p->flag=1;
j--;
}
}
s_p=s_p->next;
}
}
return j;
}
为什么我调用这个函数时,传递给形参s_head的指针没有变呢? 展开
{
struct soldier *s_p,*s_q;
int i=1,j=c,k=0;
s_head=s_p=s_q=0;
for(;i<=c;i++)
{
s_p=(struct soldier *)malloc(sizeof(struct soldier));
s_p->number=i;
s_p->flag=0;
s_p->id=i;
if(s_head==NULL)
s_head=s_p;
else
s_q->next=s_p;
s_q=s_p;
}
s_p=s_head;
while(j>=m)
{
s_p=s_head;
k=1;
while(s_p)
{
if(s_p->flag==0)
{
if(s_p->number%m==0)
{
s_p->number=k++;
}
else
{
s_p->flag=1;
j--;
}
}
s_p=s_p->next;
}
}
return j;
}
为什么我调用这个函数时,传递给形参s_head的指针没有变呢? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询