Ϊʲôһֱ¸³Öµ²»ÁË
#include<stdio.h>struct List
{
int i;
int l;
char qq;
char email;
struct List *a;
};
int k=0;
void input(struct List *a);
void input(struct List *a)
{
printf("ÇëÊäÈëµÚ %d ¸öѧÉúµÄÊý¾Ý...\n",k+1);
printf("ÇëÊäÈëѧÉúµÄID:");
scanf("%d",&a->i); //Ò»Ö±³ö´í
printf("ÇëÊäÈëѧÉúµÄÐÔ±ð(1/0)(ÄÐ/Å®):");
scanf("%d",&a->l );
getchar();
printf("ÇëÊäÈëQQºÅ:");
scanf("%s",&a->qq);
getchar();
printf("ÇëÊäÈëEmailµØÖ·:");
scanf("%s",a->email);
getchar();
if(k>5)
{
return;
}
else
{
k++;
input(a->a);
}
}
int n=0,l=0;
void print(struct List *a);
void print(struct List *a)
{
printf("ÒÔÏÂÊÇËùÓÐÄÐÉúµÄÊý¾Ý£º\n");
{
if(n>5)
{
return;
}
else
{
if(a->l==1 )
{
printf("ID:%d\n",a->i );
printf("QQ:%s\n",a->qq);
printf("Email:%s",a->email );
}
n++;
print(a->a );
}
}
printf("ÒÔÏÂÊÇÅ®ÉúµÄÊý¾Ý£º\n");
{
if(l>5)
{
return;
}
else
{
if(a->l==1 )
{
printf("ID:%d\n",a->i );
printf("QQ:%s\n",a->qq );
printf("Email:%s",a->email );
}
l++;
print(a->a );
}
}
}
int main(void)
{
struct List *a;
input(a);
print(a);
return 0;
} ±¾Ìû×îºóÓÉ ¸èÕßÎÄÃ÷ÇåÀíÔ± ÓÚ 2023-6-4 16:20 ±à¼
Õâ¶Î´úÂë³öÏÖ´íÎóµÄÔÒòÊÇÒòΪ´«µÝ¸øÊäÈ뺯Êý input µÄ½á¹¹ÌåÖ¸Õë a ÊÇδ³õʼ»¯µÄ£¬ËùÒÔÔÚ¶ÔÆä½øÐи³ÖµÊ±¾Í»á³öÏÖÎÊÌâ¡£ÕýÈ·µÄ×ö·¨Ó¦¸ÃÊÇÏȶ¯Ì¬·ÖÅäÄÚ´æÀ´Îª½á¹¹ÌåÖ¸Õë±äÁ¿·ÖÅä¿Õ¼ä£¬ÔÚ³ÌÐò×ʼ²¿·ÖÌí¼ÓÈçÏ´úÂë¼´¿É£º
c
struct List *a = NULL;
a = (struct List *)malloc(sizeof(struct List));
ÐèҪעÒâµÄÊÇ£¬ÔÚ³ÌÐò½áÊøʱÐèÒªÊÖ¶¯ÊÍ·ÅÒѾ·ÖÅäµÄÄڴ棬·ñÔò»áµ¼ÖÂÄÚ´æй©¡£´ËÍ⣬ÔÚͨ¹ý scanf º¯Êý»ñÈ¡ÊäÈëʱ£¬%s ²»ÄÜ¼Ó &£¬ÒòΪÔÚÊý×éÃûÖÐʹÓÃʱÊý×éÃû¼´ÎªÊý×éÊ×ÔªËصĵØÖ·£¬Ó¦Ö±½Ó½«Êý×éÃû×÷Ϊ²ÎÊý´«Èë¡£ÁíÍ⣬ÓÉÓÚÅ®ÉúÊý¾ÝµÄÊä³öºÍÄÐÉúÊý¾ÝµÄÊä³öÂß¼Ïàͬ£¬ËùÒÔÕâÁ½¸ö²¿·ÖµÄ´úÂë¿ÉÒԺϲ¢µ½Ò»¸öÑ»·ÖС£
Ð޸ĺóµÄ´úÂëÈçÏ£º
#include<stdio.h>
#include<stdlib.h>
struct List
{
int i;
int l;
char qq;
char email;
struct List *a;
};
int k=0;
void input(struct List *a);
void input(struct List *a)
{
printf("ÇëÊäÈëµÚ %d ¸öѧÉúµÄÊý¾Ý...\n",k+1);
printf("ÇëÊäÈëѧÉúµÄID:");
scanf("%d",&a->i); //Ò»Ö±³ö´í
printf("ÇëÊäÈëѧÉúµÄÐÔ±ð(1/0)(ÄÐ/Å®):");
scanf("%d",&a->l );
getchar();
printf("ÇëÊäÈëQQºÅ:");
scanf("%s", a->qq);
getchar();
printf("ÇëÊäÈëEmailµØÖ·:");
scanf("%s", a->email);
getchar();
if(k>5)
{
return;
}
else
{
k++;
a->a = (struct List *)malloc(sizeof(struct List)); // ¶¯Ì¬·ÖÅäÄÚ´æ
input(a->a);
}
}
int n=0,l=0;
void print(struct List *a);
void print(struct List *a)
{
printf("ÒÔÏÂÊÇËùÓÐÄÐÉúµÄÊý¾Ý£º\n");
while(a != NULL)
{
if(n>=5 || a->a == NULL)
{
break;
}
else if(a->l==1)
{
printf("ID:%d\n",a->i );
printf("QQ:%s\n",a->qq);
printf("Email:%s\n\n",a->email );
}
n++;
a = a->a;
}
printf("ÒÔÏÂÊÇÅ®ÉúµÄÊý¾Ý£º\n");
while(a != NULL)
{
if(l>=5 || a->a == NULL)
{
break;
}
else if(a->l==0)
{
printf("ID:%d\n",a->i );
printf("QQ:%s\n",a->qq );
printf("Email:%s\n\n",a->email );
}
l++;
a = a->a;
}
}
int main(void)
{
struct List *a = NULL;
a = (struct List *)malloc(sizeof(struct List));
input(a);
print(a->a);
// ÊͷŶ¯Ì¬·ÖÅäµÄÄÚ´æ
while(a != NULL)
{
struct List *tmp = a;
a = a->a;
free(tmp);
}
return 0;
} ¸Ðл¸Ðл
Ò³:
[1]