for语句循环时
#include<stdio.h>#include<malloc.h>
#define LEN sizeof(struct person)
#define NULL 0
struct person
{
int num;
int code;
struct person *next;
};
int j=1,n=0;
struct person *creat0()
{
struct person p[13];
int i;
i=0;
while(i<13)
{
n++;
p[i].num=i+1;
i++;
}
return p;
}
//下面的for循环怎么i=n时,i自动变为0
struct person *creat1(struct person p[])
{
int i;
for(i=0;i<n;i++)
{
p[i].code=j;
j++;
if(j==3) j=0;
}
return p;
}
void print(struct person head[])
{
struct person *p;
printf("Now,these records are:\n");
if(head!=NULL)
do{
printf("%d %d",p->num,p->code);
p=p->next;
}while(p!=NULL);
}
struct person *del(struct person head[])
{
struct person *p1,*p2;
p1=head;
while(p1->code!=0&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->code==0)
{
if(p1==head) head=p1->next;
else p2->next=p1->next;
n--;
}
return head;
}
void main()
{
struct person *head;
head=creat0();
head=creat1(head);
while(n>1)
{
head=del(head);
head=creat1(head);
}
print(head);
}
第二个for语句怎么会无限循环,请问时什么原因