| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 493 人关注过本帖, 1 人收藏
标题:求帮忙找错!:手机通讯录浏览,查询,删除操作
取消只看楼主 加入收藏
影随风
Rank: 2
等 级:论坛游民
帖 子:38
专家分:24
注 册:2013-3-14
结帖率:85.71%
收藏(1)
已结贴  问题点数:20 回复次数:0 
求帮忙找错!:手机通讯录浏览,查询,删除操作
我做的简单地通讯录系统,其中的浏览,查询,删除这三个操作有问题但是我又找不到在哪里,麻烦大家帮忙找一找,改一改!谢谢!
#include<stdio.h>
#include<string.h>
struct friends_list
{
 char  name[10],weixin[20],email[30],sex[2];
 long  qq,bd,tele;
 int   age;
};
int Count=0;
void new_friend(struct friends_list frients[]);
void search_friend1(struct friends_list friends[],char *name);
void search_friend2(struct friends_list friends[],char *tele);
void liulan_friend(struct friends_list friends[]);
void delete_friend(struct friends_list friends[]);
void gengxin_friend(struct friends_list friends[]);

int main(void)
{
 int choice,choice1,age;
 long qq,bd,tele;
 char  name[10],weixin[20],email[30],sex[2];
 struct friends_list friends[1000];
 do
 {
  printf("1:新建 2:浏览 3:删除 4:更新  5:查询 0:退出\n ");
  printf("请选择0~5号功能键\n");
  scanf("%d",&choice);
    if(choice>=0 && choice<=5)
     {
        switch(choice)
        {
        case 1:
            new_friend(friends);   
            break;
        case 2:
            liulan_friend(friends);
            break;
        case 3:
            delete_friend(friends);
            break;
        case 4:
            gengxin_friend(friends);
            break;

         case 5:
              do
              {
                printf("1:按姓名查询 2:按电话号码查询 0:退出查询\n");
                scanf("%d",&choice1);
                if(choice1>=0&&choice1<=2)
                {
                    switch(choice1)
                    {
                        case 1:        
                            search_friend1(friends,name);
                            break;
                        case 2:            
                            search_friend2(friends,name);
                            break;
                        case 0:break;
                    }
                }
                else printf("输入错误!请输入0~2号功能键!\n");
              }while(choice1!=0);        
         case 0:break;
        }
     }
    else
          printf("输入错误!请输入0~5号功能键!\n");
}while(choice!=0);
 
 printf("感谢您使用本通讯录,欢迎下次使用\n");
   
  return 0;
}
/*新建通讯录*/
void new_friend(struct friends_list friends[])
{
    struct friends_list f;
    FILE  *fp;
   
    if(Count==1000)
    {
     printf("通讯录已满\n");                        
                                                                                                
    return ;
    }
    else
    {
        printf("请输入新的联系人\n姓名:");
        scanf("%s",f.name);
        printf("年龄:\n");
        scanf("%d",&f.age);
        printf("电话:\n");
        scanf("%ld",&f.tele);
        printf("qq:\n");
        scanf("%ld",&f.qq);
        printf("微信:\n");
        scanf("%s",f.weixin);
        printf("生日:\n");
        scanf("%ld",&f.bd);
        printf("电子邮件:\n");
        scanf("%s",f.email);
        printf("性别:\n");
        scanf("%s",f.sex);
        friends[Count]=f;
        if((fp=fopen("f1.txt","a+"))==NULL)
        {
            printf("File open error!\n");
            exit(0);
        }
        fprintf(fp,"%s%  d%15ld%11ld%11s%9lds%18s%4s\n",friends[Count].name,friends[Count].age,friends[Count].tele,friends[Count].qq,friends[Count].weixin,friends[Count].bd,friends[Count].email,friends[Count].sex);
        if(fclose(fp))
        {
            printf("Can not close the file !\n");
            exit(0);
        }
    }
     Count++;
}
/*按姓名查询*/
void search_friend1(struct friends_list friends[],char *name)
{
    FILE  *fp;
 struct  friends_list g;

    int count=0;

    printf("请输入你要查找的姓名:\n");
    scanf("%s",name);
    if((fp=fopen("f1.txt","r"))==NULL)
    {
        printf("File open error!\n");
        exit(0);
    }
    while(!feof(fp))
    {   
        fscanf(fp,"%s%d%ld%ld%s%ld%s%s",g.name,g.age,g.tele,g.qq,g.weixin,g.bd,g.email,g.sex);
        if(strcmp(g.name,name)==0)
        {
            printf(" 姓名  年领  电话          QQ        微信      生日         电子邮件     性别  \n");   
            printf("%s%  d%13ld%11ld%11s%9ld%18s%4s\n",g.name,g.age,g.tele,g.qq,g.weixin,g.bd,g.email,g.sex);
            count=1;
            gengxin_friend(friends);
            break;
        }   
    }
    if(fclose(fp))
    {
        printf("Can not close the file!\n");
        exit(0);
    }
}
/*按号码查询*/
 void search_friend2(struct friends_list friends[],char *tele)
 {
    FILE  *fp;
 struct  friends_list g;

    int count=0;

    printf("请输入你要查找的号码:\n");
    scanf("%ld",tele);
    if((fp=fopen("f1.txt","r"))==NULL)
    {
        printf("File open error!\n");
        exit(0);
    }
    while(!feof(fp))
    {   
        fscanf(fp,"%s%d%ld%ld%s%ld%s%s",g.name,g.age,g.tele,g.qq,g.weixin,g.bd,g.email,g.sex);
        if(g.tele==tele)
        {
            printf(" 姓名  年龄  电话          QQ        微信      生日         电子邮件     性别  \n");   
            printf("%s%4d%13ld%11ld%11s%9ld%18s%5s\n",g.name,g.age,g.tele,g.qq,g.weixin,g.bd,g.email,g.sex);
            count=1;
            gengxin_friend(friends);
            break;
        }
        else printf("无此联系人或者输入错误!\n");
   
    }
    if(fclose(fp))
    {
        printf("Can not close the file!\n");
        exit(0);
    }
}
/*浏览操作*/
void liulan_friend(struct friends_list friends[],int Count)
{
    int i=0;        
    struct  friends_list g;
    FILE  *fp=fopen("f1.txt","r");
    printf(" 姓名  年领  电话          QQ        微信      生日         电子邮件     性别  \n");
    if(!fp)
    {
        printf("File open error!\n");   
    }
    while(!feof(fp))
    {
        fscanf(fp,"%s%d%ld%ld%s%ld%s%s",g.name,g.age,g.tele,g.qq,g.weixin,g.bd,g.email,g.sex);
        printf("%s%4d%13ld%11ld%11s%9ld%18s%5s\n",g.name,g.age,g.tele,g.qq,g.weixin,g.bd,g.email,g.sex);
    }
    if(fclose(fp))
    {
        printf("Can not close the file!\n");
        exit(0);
    }
   
}
/*删除操作*/
void delete_friend(struct friends_list friends[])
{
    FILE  *fp;
    struct  friends_list g[1000];
    int    n,j=0,i=0;
    char   name[10],tele[10];
    printf("请输入联系人:1:姓名  2:电话  0:退出\n");
    scanf("%d",&n);
    switch(n)
    {
        case 1:
            printf("姓名:");
            scanf("%s",name);
            if((fp=fopen("f1.txt","r"))==NULL)
            {
                printf("File open error!\n");
                exit(0);
            }
            while(!feof(fp))
            {
                fscanf(fp,"%s%    d%ld%ld%s%ld%s%s",g[i].name,g[i].age,g[i].tele,g[i].qq,g[i].weixin,g[i].bd,g[i].email,g[i].sex);
                i++;
            
            }   
               
            if(fclose(fp))
            {
                printf("Can not close the file!\n");
                exit(0);
            }
        
               
            if((fp=fopen("f1.txt","a+"))==NULL)
            {
                printf("File open error!\n");
                exit(0);
            }
            
            while(!feof(fp))
            {
                j=0;
                if(g[j].name!=name)
                    fprintf(fp,"%s%4d%13f%11f%11s%9f%18s%5s\n",g[j].name,g[j].age,g[j].tele,g[j].qq,g[j].weixin,g[j].bd,g[j].email,g[j].sex);
                j++;            
            }                    
            if(fclose(fp))
            {
                printf("Can not close the file!\n");
                exit(0);
            }
            break;
        case 2:
            printf("电话:");
            scanf("%ld",tele);
                if((fp=fopen("f1.txt","r"))==NULL)
            {
                printf("File open error!\n");
                exit(0);
            }
            while(!feof(fp))
            {
                fscanf(fp,"%s%    f%ld%ld%s%ld%s%s",g[i].name,g[i].age,g[i].tele,g[i].qq,g[i].weixin,g[i].bd,g[i].email,g[i].sex);
                i++;            
            }                    
            if(fclose(fp))
            {
                printf("Can not close the file!\n");
                exit(0);
            }               
            if((fp=fopen("f1.txt","a+"))==NULL)
            {
                printf("File open error!\n");
                exit(0);
            }            
            while(!feof(fp))
            {    j=0;
                if(g[j].tele!=tele)
                fprintf(fp,"%s%    d%13f%11f%11s%9f%18s%5s\n",g[i].name,g[i].age,g[i].tele,g[i].qq,g[i].weixin,g[i].bd,g[i].email,g[i].sex);
                j++;            
            }               
            if(fclose(fp))
            {
                printf("Can not close the file!\n");
                exit(0);
            }
            break;
        case  0:
            break;
    }while(n!=0);
}
void gengxin_friend(struct friends_list friends[])
{




}
搜索更多相关主题的帖子: void 查询 friends include 
2013-05-11 22:32
快速回复:求帮忙找错!:手机通讯录浏览,查询,删除操作
数据加载中...
 
   



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

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