标题:编程错误但是我找不出来!
只看楼主
yunnandaxue
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2008-11-19
结帖率:100%
已结贴  问题点数:20 回复次数:2 
编程错误但是我找不出来!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define H "--------------------"
typedef struct person
{
        char name[10];
        char addr[20];
        char tele[10];
        char qq[10];
        struct person *next;
}PERSON;
PERSON *head;
void lcreate()
{
     PERSON *pb;
     char ch;
     do
     {
          pb=(PERSON *)malloc(sizeof(PERSON));
          if(!pb)
          {
                 printf("内存分配失败!\n");
                 getch();
                 exit(1);
          }
          printf("%s\n",H);
          printf("姓名:");
          gets(pb->name);
          printf("地址:");
          gets(pb->addr);
          printf("电话:");
          gets(pb->tele);
          printf("QQ:");
          gets(pb->qq);
          linsert(pb);
          printf("\n继续输入下一人的信息(y/n)?");
          ch=getchar();
          fflush(stdin);
         
     }while(ch=='y'||ch=='Y');
}
void linsert(PERSON *p)
{
     PERSON *pa,*pb;
     pb=head;
     if(head==NULL)
     head=p;
     else
     {
         while(pb)
         {
               pa=pb;
               pb=pb->next;   
         }
         pa->next=p;
     }
     p->next=NULL;
}
void ldisp()
{
     PERSON *pa;
     pa=head;
     while(pa)
     {
           printf("%s\n",H);
           printf("姓名:%s\n",pa->name);
           printf("地址:%s\n",pa->addr);
           printf("电话:%s\n",pa->tele);
           printf("QQ:%s\n",pa->qq);
           pa=pa->next;   
     }
}
PERSON *lsearch(char *name)
{
       PERSON *pa;
       pa=head;
       while(pa)
       {
             if(strcmp(name,pa->name))
             pa=pa->next;
             else
             return pa;   
       }
       return NULL;
}
void ldel(char *name)
{
     PERSON *pb,*pa;
     if(head==NULL)
     {
        printf("链表为空!\n");
        getch();
        exit(1);           
     }
     pb=head;
     while(strcmp(pb->name,name)&&pb->next)
     {
           pa=pb;
           pb=pb->next;                                
     }
     if(!strcmp(pb->name,name))
     {
        if(pb==head)
        head=pb->next;
        else
        pa->next=pb->next;
        free(pb);                       
     }
}
int main()
{
    PERSON *pf;
    char ch,name[10];
    head=NULL;
    do
    {
           printf("%s\n",H);
           printf("1-增加链表结点\n");
           printf("2-查找链表结点\n");
           printf("3-查看链表结点\n");
           printf("4-删除链表结点\n");   
           printf("0-退出程序\n");
           printf("%s\n",H);
           printf("\n请选择功能(0~4):");
           ch=getchar();
           fflush(stdin);
           switch(ch)
           {
                     case '1':
                          {
                              lcreate();
                              break;
                          }
                     case '2':
                          {
                              printf("\n请输入查找姓名:");
                              gets(name);
                              pf=lsearch(name);
                              if(pf==NULL)
                              printf("\n在链表中未找到%s的信息!\n",name);
                              else
                              {
                                  printf("%s\n",H);
                                  pintnf("\n姓名:%s\n",pf->name);
                                  printf("地址:%s\n",pf->addr);
                                  printf("电话:%s\n",pf->tele);
                                  printf("QQ:%s\n",pf->qq);
                                  printf("%s\n",H);
                              }
                              break;
                          }     
                      case '3':
                           {
                               ldisp();
                               break;
                           }   
                      case '4':
                           {
                               printf("\n请输入需要删除的姓名:");
                               gets(name);
                               ldel(name);
                               break;
                           }
           }
    }while(ch!='0');
}
这是我照书上抄的,本人检查过,和书上一摸一样,可是编译的时候总是说void linsert(PERSON *p)
{
这块错!请高手指教!
搜索更多相关主题的帖子: person include 
2009-08-11 17:36
yunnandaxue
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2008-11-19
得分:0 
没有人么
2009-08-11 17:57
灵动心境
Rank: 2
等 级:论坛游民
帖 子:12
专家分:66
注 册:2009-8-1
得分:20 
改成下面这样就可以了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define H "--------------------"
typedef struct person
{
        char name[10];
        char addr[20];
        char tele[10];
        char qq[10];
        struct person *next;
}PERSON;
PERSON *head;
void linsert(PERSON *p)
{
     PERSON *pa,*pb;
     pb=head;
     if(head==NULL)
     head=p;
     else
     {
         while(pb)
         {
               pa=pb;
               pb=pb->next;   
         }
         pa->next=p;
     }
     p->next=NULL;
}
void lcreate()
{
     PERSON *pb;
     char ch;
     do
     {
          pb=(PERSON *)malloc(sizeof(PERSON));
          if(!pb)
          {
                 printf("内存分配失败!\n");
                /* getch();*/
                 exit(1);
          }
          printf("%s\n",H);
          printf("姓名:");
          gets(pb->name);
          printf("地址:");
          gets(pb->addr);
          printf("电话:");
          gets(pb->tele);
          printf("QQ:");
          gets(pb->qq);
          linsert(pb);
          printf("\n继续输入下一人的信息(y/n)?");
          ch=getchar();
          fflush(stdin);
           
     }while(ch=='y'||ch=='Y');
}
 
void ldisp()
{
     PERSON *pa;
     pa=head;
     while(pa)
     {
           printf("%s\n",H);
           printf("姓名:%s\n",pa->name);
           printf("地址:%s\n",pa->addr);
           printf("电话:%s\n",pa->tele);
           printf("QQ:%s\n",pa->qq);
           pa=pa->next;   
     }
}
PERSON *lsearch(char *name)
{
       PERSON *pa;
       pa=head;
       while(pa)
       {
             if(strcmp(name,pa->name))
             pa=pa->next;
             else  
             return pa;   
       }
       return NULL;
}
void ldel(char *name)
{
     PERSON *pb,*pa;
     if(head==NULL)
     {
        printf("链表为空!\n");
      /*  getch();*/
        exit(1);            
     }
     pb=head;
     while(strcmp(pb->name,name)&&pb->next)
     {
           pa=pb;
           pb=pb->next;                                 
     }
     if(!strcmp(pb->name,name))
     {
        if(pb==head)
        head=pb->next;
        else
        pa->next=pb->next;
        free(pb);                        
     }
}
int main()
{
    PERSON *pf;
    char ch,name[10];
    head=NULL;
    do
    {
           printf("%s\n",H);
           printf("1-增加链表结点\n");
           printf("2-查找链表结点\n");
           printf("3-查看链表结点\n");
           printf("4-删除链表结点\n");   
           printf("0-退出程序\n");
           printf("%s\n",H);
           printf("\n请选择功能(0~4):");
           ch=getchar();
           fflush(stdin);
           switch(ch)
           {
                     case '1':
                          {
                              lcreate();
                              break;
                          }
                     case '2':
                          {
                              printf("\n请输入查找姓名:");
                              gets(name);
                              pf=lsearch(name);
                              if(pf==NULL)
                              printf("\n在链表中未找到%s的信息!\n",name);
                              else
                              {
                                  printf("%s\n",H);
                                  printf("\n姓名:%s\n",pf->name);  //这里应该为printf
                                  printf("地址:%s\n",pf->addr);
                                  printf("电话:%s\n",pf->tele);
                                  printf("QQ:%s\n",pf->qq);
                                  printf("%s\n",H);
                              }
                              break;
                          }      
                      case '3':
                           {
                               ldisp();
                               break;
                           }     
                      case '4':
                           {
                               printf("\n请输入需要删除的姓名:");
                               gets(name);
                               ldel(name);
                               break;
                           }
           }
    }while(ch!='0');
}
2009-08-11 20:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-282285-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052192 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved