ÓãCÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
²é¿´: 554|»Ø¸´: 2

[Òѽâ¾ö]Ϊʲôһֱ¸³Öµ²»ÁË

[¸´ÖÆÁ´½Ó]
·¢±íÓÚ 2023-6-4 16:17:56 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ

ÂíÉÏ×¢²á£¬½á½»¸ü¶àºÃÓÑ£¬ÏíÓøü¶à¹¦ÄÜ^_^

ÄúÐèÒª µÇ¼ ²Å¿ÉÒÔÏÂÔØ»ò²é¿´£¬Ã»ÓÐÕ˺ţ¿Á¢¼´×¢²á

x
#include<stdio.h>

struct List
{
        int i;
        int l;
        char qq[10];
        char email[16];
        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:18:59
±¾Ìû×îºóÓÉ ¸èÕßÎÄÃ÷ÇåÀíÔ± ÓÚ 2023-6-4 16:20 ±à¼­

Õâ¶Î´úÂë³öÏÖ´íÎóµÄÔ­ÒòÊÇÒòΪ´«µÝ¸øÊäÈ뺯Êý input µÄ½á¹¹ÌåÖ¸Õë a ÊÇδ³õʼ»¯µÄ£¬ËùÒÔÔÚ¶ÔÆä½øÐи³ÖµÊ±¾Í»á³öÏÖÎÊÌâ¡£ÕýÈ·µÄ×ö·¨Ó¦¸ÃÊÇÏȶ¯Ì¬·ÖÅäÄÚ´æÀ´Îª½á¹¹ÌåÖ¸Õë±äÁ¿·ÖÅä¿Õ¼ä£¬ÔÚ³ÌÐò×ʼ²¿·ÖÌí¼ÓÈçÏ´úÂë¼´¿É£º

c
  1. struct List *a = NULL;
  2. a = (struct List *)malloc(sizeof(struct List));
¸´ÖÆ´úÂë

ÐèҪעÒâµÄÊÇ£¬ÔÚ³ÌÐò½áÊøʱÐèÒªÊÖ¶¯ÊÍ·ÅÒѾ­·ÖÅäµÄÄڴ棬·ñÔò»áµ¼ÖÂÄÚ´æй©¡£´ËÍ⣬ÔÚͨ¹ý scanf º¯Êý»ñÈ¡ÊäÈëʱ£¬%s ²»ÄÜ¼Ó &£¬ÒòΪÔÚÊý×éÃûÖÐʹÓÃʱÊý×éÃû¼´ÎªÊý×éÊ×ÔªËصĵØÖ·£¬Ó¦Ö±½Ó½«Êý×éÃû×÷Ϊ²ÎÊý´«Èë¡£ÁíÍ⣬ÓÉÓÚÅ®ÉúÊý¾ÝµÄÊä³öºÍÄÐÉúÊý¾ÝµÄÊä³öÂß¼­Ïàͬ£¬ËùÒÔÕâÁ½¸ö²¿·ÖµÄ´úÂë¿ÉÒԺϲ¢µ½Ò»¸öÑ­»·ÖС£

Ð޸ĺóµÄ´úÂëÈçÏ£º

  1. #include<stdio.h>
  2. #include<stdlib.h>

  3. struct List
  4. {
  5.     int i;
  6.     int l;
  7.     char qq[10];
  8.     char email[16];
  9.     struct List *a;
  10. };

  11. int k=0;

  12. void input(struct List *a);
  13. void input(struct List *a)
  14. {
  15.     printf("ÇëÊäÈëµÚ %d ¸öѧÉúµÄÊý¾Ý...\n",k+1);
  16.     printf("ÇëÊäÈëѧÉúµÄID:");
  17.     scanf("%d",&a->i);   //Ò»Ö±³ö´í
  18.    
  19.     printf("ÇëÊäÈëѧÉúµÄÐÔ±ð(1/0)(ÄÐ/Å®):");
  20.     scanf("%d",&a->l );
  21.     getchar();
  22.    
  23.     printf("ÇëÊäÈëQQºÅ:");
  24.     scanf("%s", a->qq);
  25.     getchar();
  26.    
  27.     printf("ÇëÊäÈëEmailµØÖ·:");
  28.     scanf("%s", a->email);
  29.     getchar();
  30.    
  31.     if(k>5)
  32.     {
  33.         return;
  34.     }
  35.     else
  36.     {
  37.         k++;
  38.         a->a = (struct List *)malloc(sizeof(struct List)); // ¶¯Ì¬·ÖÅäÄÚ´æ
  39.         input(a->a);
  40.     }
  41. }

  42. int n=0,l=0;
  43. void print(struct List *a);
  44. void print(struct List *a)
  45. {
  46.     printf("ÒÔÏÂÊÇËùÓÐÄÐÉúµÄÊý¾Ý£º\n");
  47.     while(a != NULL)
  48.     {
  49.         if(n>=5 || a->a == NULL)
  50.         {
  51.             break;
  52.         }
  53.         else if(a->l==1)
  54.         {
  55.             printf("ID:%d\n",a->i );
  56.             printf("QQ:%s\n",a->qq);
  57.             printf("Email:%s\n\n",a->email );
  58.         }
  59.         n++;
  60.         a = a->a;
  61.     }      
  62.     printf("ÒÔÏÂÊÇÅ®ÉúµÄÊý¾Ý£º\n");
  63.     while(a != NULL)
  64.     {
  65.         if(l>=5 || a->a == NULL)
  66.         {
  67.             break;
  68.         }
  69.         else if(a->l==0)
  70.         {
  71.             printf("ID:%d\n",a->i );
  72.             printf("QQ:%s\n",a->qq );
  73.             printf("Email:%s\n\n",a->email );
  74.         }
  75.         l++;
  76.         a = a->a;
  77.     }      
  78. }

  79. int main(void)
  80. {
  81.     struct List *a = NULL;
  82.     a = (struct List *)malloc(sizeof(struct List));
  83.    
  84.     input(a);
  85.    
  86.     print(a->a);
  87.    
  88.     // ÊͷŶ¯Ì¬·ÖÅäµÄÄÚ´æ
  89.     while(a != NULL)
  90.     {
  91.         struct List *tmp = a;
  92.         a = a->a;
  93.         free(tmp);
  94.     }
  95.    
  96.     return 0;
  97. }
¸´ÖÆ´úÂë
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
·¢±íÓÚ 2023-6-4 16:18:59 | ÏÔʾȫ²¿Â¥²ã    ±¾Â¥Îª×î¼Ñ´ð°¸   
±¾Ìû×îºóÓÉ ¸èÕßÎÄÃ÷ÇåÀíÔ± ÓÚ 2023-6-4 16:20 ±à¼­

Õâ¶Î´úÂë³öÏÖ´íÎóµÄÔ­ÒòÊÇÒòΪ´«µÝ¸øÊäÈ뺯Êý input µÄ½á¹¹ÌåÖ¸Õë a ÊÇδ³õʼ»¯µÄ£¬ËùÒÔÔÚ¶ÔÆä½øÐи³ÖµÊ±¾Í»á³öÏÖÎÊÌâ¡£ÕýÈ·µÄ×ö·¨Ó¦¸ÃÊÇÏȶ¯Ì¬·ÖÅäÄÚ´æÀ´Îª½á¹¹ÌåÖ¸Õë±äÁ¿·ÖÅä¿Õ¼ä£¬ÔÚ³ÌÐò×ʼ²¿·ÖÌí¼ÓÈçÏ´úÂë¼´¿É£º

c
  1. struct List *a = NULL;
  2. a = (struct List *)malloc(sizeof(struct List));
¸´ÖÆ´úÂë

ÐèҪעÒâµÄÊÇ£¬ÔÚ³ÌÐò½áÊøʱÐèÒªÊÖ¶¯ÊÍ·ÅÒѾ­·ÖÅäµÄÄڴ棬·ñÔò»áµ¼ÖÂÄÚ´æй©¡£´ËÍ⣬ÔÚͨ¹ý scanf º¯Êý»ñÈ¡ÊäÈëʱ£¬%s ²»ÄÜ¼Ó &£¬ÒòΪÔÚÊý×éÃûÖÐʹÓÃʱÊý×éÃû¼´ÎªÊý×éÊ×ÔªËصĵØÖ·£¬Ó¦Ö±½Ó½«Êý×éÃû×÷Ϊ²ÎÊý´«Èë¡£ÁíÍ⣬ÓÉÓÚÅ®ÉúÊý¾ÝµÄÊä³öºÍÄÐÉúÊý¾ÝµÄÊä³öÂß¼­Ïàͬ£¬ËùÒÔÕâÁ½¸ö²¿·ÖµÄ´úÂë¿ÉÒԺϲ¢µ½Ò»¸öÑ­»·ÖС£

Ð޸ĺóµÄ´úÂëÈçÏ£º

  1. #include<stdio.h>
  2. #include<stdlib.h>

  3. struct List
  4. {
  5.     int i;
  6.     int l;
  7.     char qq[10];
  8.     char email[16];
  9.     struct List *a;
  10. };

  11. int k=0;

  12. void input(struct List *a);
  13. void input(struct List *a)
  14. {
  15.     printf("ÇëÊäÈëµÚ %d ¸öѧÉúµÄÊý¾Ý...\n",k+1);
  16.     printf("ÇëÊäÈëѧÉúµÄID:");
  17.     scanf("%d",&a->i);   //Ò»Ö±³ö´í
  18.    
  19.     printf("ÇëÊäÈëѧÉúµÄÐÔ±ð(1/0)(ÄÐ/Å®):");
  20.     scanf("%d",&a->l );
  21.     getchar();
  22.    
  23.     printf("ÇëÊäÈëQQºÅ:");
  24.     scanf("%s", a->qq);
  25.     getchar();
  26.    
  27.     printf("ÇëÊäÈëEmailµØÖ·:");
  28.     scanf("%s", a->email);
  29.     getchar();
  30.    
  31.     if(k>5)
  32.     {
  33.         return;
  34.     }
  35.     else
  36.     {
  37.         k++;
  38.         a->a = (struct List *)malloc(sizeof(struct List)); // ¶¯Ì¬·ÖÅäÄÚ´æ
  39.         input(a->a);
  40.     }
  41. }

  42. int n=0,l=0;
  43. void print(struct List *a);
  44. void print(struct List *a)
  45. {
  46.     printf("ÒÔÏÂÊÇËùÓÐÄÐÉúµÄÊý¾Ý£º\n");
  47.     while(a != NULL)
  48.     {
  49.         if(n>=5 || a->a == NULL)
  50.         {
  51.             break;
  52.         }
  53.         else if(a->l==1)
  54.         {
  55.             printf("ID:%d\n",a->i );
  56.             printf("QQ:%s\n",a->qq);
  57.             printf("Email:%s\n\n",a->email );
  58.         }
  59.         n++;
  60.         a = a->a;
  61.     }      
  62.     printf("ÒÔÏÂÊÇÅ®ÉúµÄÊý¾Ý£º\n");
  63.     while(a != NULL)
  64.     {
  65.         if(l>=5 || a->a == NULL)
  66.         {
  67.             break;
  68.         }
  69.         else if(a->l==0)
  70.         {
  71.             printf("ID:%d\n",a->i );
  72.             printf("QQ:%s\n",a->qq );
  73.             printf("Email:%s\n\n",a->email );
  74.         }
  75.         l++;
  76.         a = a->a;
  77.     }      
  78. }

  79. int main(void)
  80. {
  81.     struct List *a = NULL;
  82.     a = (struct List *)malloc(sizeof(struct List));
  83.    
  84.     input(a);
  85.    
  86.     print(a->a);
  87.    
  88.     // ÊͷŶ¯Ì¬·ÖÅäµÄÄÚ´æ
  89.     while(a != NULL)
  90.     {
  91.         struct List *tmp = a;
  92.         a = a->a;
  93.         free(tmp);
  94.     }
  95.    
  96.     return 0;
  97. }
¸´ÖÆ´úÂë
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
 Â¥Ö÷| ·¢±íÓÚ 2023-6-4 17:02:58 | ÏÔʾȫ²¿Â¥²ã
¸Ðл¸Ðл
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | Á¢¼´×¢²á

±¾°æ»ý·Ö¹æÔò

СºÚÎÝ|ÊÖ»ú°æ|Archiver|ÓãC¹¤×÷ÊÒ ( ÔÁICP±¸18085999ºÅ-1 | ÔÁ¹«Íø°²±¸ 44051102000585ºÅ)

GMT+8, 2024-5-20 15:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí