| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 555 人关注过本帖
标题:C语言通讯录,求大神帮忙查错!
取消只看楼主 加入收藏
gsyahu
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-6-23
收藏
 问题点数:0 回复次数:0 
C语言通讯录,求大神帮忙查错!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN sizeof(struct basic_meg)
struct basic_meg *New(void)         
void List(struct basic_meg *head);
void Search(struct basic_meg *head);
struct basic_meg *Delete(struct basic_meg *head);
struct basic_meg *Insert(struct basic_meg *head);
struct basic_meg
{
    char name[20];
    char number[20];
    char email[20];
    struct basic_meg *next;
};

main()
{
    char num[10];
    struct basic_meg *head;
    while(1)
    {
        printf("--------------------------------\n");
        printf("-----1 New    calling card   -----\n");
        printf("-----2 List calling cards  -----\n");
        printf("-----3 Search calling card -----\n");
        printf("-----4 Delete calling card -----\n");
        printf("-----5 Insert calling card -----\n");
        printf("-----0 Exit                -----\n");
        printf("--------------------------------\n");
        printf("Please choice number:\n");
        gets(num);
        switch(*num)
        {
            case '1':head=New();break;
            case '2':List(head);break;
            case '3':Search();break;
            case '4':head=Delete(head);break;
            case '5':Insert();break;
            case '0':break;
            default:printf("Please enter a right number!\n");goto loop;
        }
        if(strcmp(num,"0")==0)  
            break;
    }
    return 0;
}

struct basic_meg *New(void)         
{  
    int n;
    struct student  *head;  
    struct student  *p1,*p2;
    n=0;
    p1=p2=(struct basic_meg *) malloc(LEN);
    printf("Please input name number and email.End of 0\n");
    gets(p1->name);
    gets(p1->number);
    gets(p1->email);
    head=NULL;
    while(p1->name!=0)
    {
        n+=1;
        if(n==1)
            head=p1;
        else  p2->next=p1;
        p2=p1;
        p1=(struct basic_meg *)malloc(LEN);
        printf("Please input name number and email.End of 0\n");
        gets(p1->name);
        gets(p1->number);
        gets(p1->email);
        printf("\n");
    }
    p2->next=NULL;  
    return(head);
}

void List(struct basic_meg *head)
{
    struct basic_meg *p;
    printf("\n these calling cards  are :\n");
    p=head;
    if(head!=NULL)
    do
    {
        puts(p->name);
        puts(p->number);
        puts(p->email);
        printf("\n");
        p=p->next;
    }
    while(p!=NULL);
}

void Search(struct basic_meg *head)
{
    struct basic_meg *p1,*p2;
    char name_search[20];
    printf("Please input the name you want to search:\n");
    gets(name_search);
    if(head==NULL)
    {
        printf("\n list null!\n");
        goto  end;
    }
    p1=head;
    while(name_search!=p1->name&&p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(name_search==p1->name)
    {
        if(p1==head)
            head=p1->next;
        else p2->next=p1->next;
        printf("The basic message you search is:\n");
        puts(name_search);
        n=n-1;
     }
   else puts(name_search);
   printf("is not found!\n");
   return(head);
}

struct basic_meg *Delete(struct student *head)
{
    struct basic_meg *p1,*p2;
    char name_delete[20];
    printf("Please input the name you want to delete:\n");
    gets(name_delete);
    if(head==NULL)
    {
        printf("\n list null!\n");
        goto  end;
    }
    p1=head;
    while(name_delete!=p1->name&&p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(name_delete==p1->name)
    {
        if(p1==head)
            head=p1->next;
        else p2->next=p1->next;
        printf("Successfully deleted!\n");
        n=n-1;
     }
   else puts(name_delete);
   printf("is not found!\n");
   return(head);
}

struct basic_meg *Insert(struct basic_meg *head)
{
    char name_insert[20];
    struct basic_meg *p1,*p2,*p3;
    p1=head;
    printf("Please input the name where you want to insert:\n");
    gets(name_insert);
    if(head==NULL)
    {
        printf("\n list null!\n");
        goto  end;
    }
    while(name_insert!=p1->name&&p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(name_insert==p1->name)
    {
        p2=p1;
        p3=p1->next;
        p1=(struct student *) malloc(LEN);
        printf("Please input name number and email.End of 0\n");
        gets(p1->name);
        gets(p1->number);
        gets(p1->email);
        p2->next=p1;
        p1->next=p3;
    }
    else puts(name_insert);
    printf("is not found!\n");
    return(head);
}
搜索更多相关主题的帖子: include 通讯录 number C语言 email 
2013-06-23 21:08
快速回复:C语言通讯录,求大神帮忙查错!
数据加载中...
 
   



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

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