| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 503 人关注过本帖, 1 人收藏
标题:通讯录管理系统 除了能录入数据 其它功能为什么都用不了
只看楼主 加入收藏
longgejiaoni
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-10-25
结帖率:0
收藏(1)
已结贴  问题点数:20 回复次数:5 
通讯录管理系统 除了能录入数据 其它功能为什么都用不了
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
  struct yhxx
  {
      char name[20];
      char email[20];
      char tele[20];
      char address[20];
  }yh[1000];
void add()                               /*添加数据*/
{
     int i,j,n=0; FILE *fp;char ch;
   do
   {  i=n;
   
        printf("请输入第%d条数据:姓名,电话,手机\n",n+1);
        scanf("%s%s%s%s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
         n++;
         getchar();
         printf("请继续添加数据(y/n?)");
         ch=getchar();  
   }    while(ch=='y'||ch=='Y');
        if((fp=fopen("c:\\vc\\a2.txt","a"))==NULL)
        {
        printf("不能打开文件\n");
        exit(0);
        }
       for(j=0;j<n;j++)
        fprintf(fp,"%15s%15s%15s%15s\n",yh[j].name,yh[j].email,yh[j].tele,yh[j].address);
         fclose(fp);
}


void chaxing(char nam[])     /*按姓名查询:*/
{
    FILE *fp;
    int i;
      if((fp=fopen("c:\\vc\\a2.txt","r"))==NULL)
   {
        printf("不能打开文件\n");
        exit(0);
   }
   do
   {
         fread(&yh[i],sizeof(struct yhxx),1,fp);
         if(strcmp(nam,yh[i].name)==0)
   {
              puts(yh[i].name);
              puts(yh[i].email);
              puts(yh[i].tele);
               puts(yh[i].address);
              printf("\n");
             break;
   }
   }while(!feof(fp));                       /*是否到文件夹末尾*/
           if(feof(fp))
          printf("查无此人\n");
}
 
void chaemail(char nam[])                 /*按email查询*/
{  
    FILE *fp;
      int i;
       if((fp=fopen("c:\\vc\\a2.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
          i=0;
 do
 {
         fread(&yh[i],sizeof(struct yhxx),1,fp);
             if(strcmp(nam,yh[i].email)==0)
    {   
          puts(yh[i].name);
          puts(yh[i].email);
          puts(yh[i].tele);
          puts(yh[i].address);
          printf("\n");break;
    }
 } while(!feof(fp));
       if(feof(fp))  printf("查无此人\n");
}
 
void chashou(char nam[])      /*按手机号查询*/
{     
   FILE *fp; int i;
       if((fp=fopen("c:\\vc\\a2.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
       i=0;
       do
    {   fread(&yh[i],sizeof(struct yhxx),1,fp);
           if(strcmp(nam,yh[i].address)==0)
     {
               puts(yh[i].name);
               puts(yh[i].email);
               puts(yh[i].tele);
               puts(yh[i].address);
               printf("\n");
                  break;
     }
    }while(!feof(fp));                         /*是否到文件夹末尾*/
      if(feof(fp)) printf("查无此人\n");
}
 
void xxcx()                                            /*信息查询*/
{              
      char nam[20];
      int sel;
     do
  {  
         printf("----------信息查询----------\n");
         printf("----------------------------\n");
         printf("1:按姓名查询  \n");
         printf("2:按email查询  \n");
         printf("3:按手机查询  \n");
         printf("0:退出        \n");
         printf("  请选择0-3\n"       );
         printf("----------------------------\n");
            scanf("%d",&sel);
            getchar();
          switch(sel)
    {
             case 1: printf("请输入姓名\n");gets(nam);
                     chaxing(nam);break;
             case 2: printf("请输入email\n");gets(nam);
                     chaemail(nam);break;
             case 3: printf("请输入手机\n");gets(nam);
                     chashou(nam);break;
             case 0:   exit(0);
    default:  printf("请输入0-4\n");      
    }
  }while(1);
}
 void edits(char nam[])                             /*信息修改*/
{  
FILE *fp;
int i=0,n;
char yhdh[20],yhm[20],eml[20],ad[20];
    printf("输入修改后的姓名、email、电话和地址");
     gets(yhm);
     gets(eml);
     gets(yhdh);
     gets(ad);
    if((fp=fopen("c:\\vc\\a2.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
while(!feof(fp))
{   fscanf(fp,"%s%s%s%s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
     if(strcmp(nam,yh[i].name)==0)
  {  strcpy(yh[i].name,yhm);strcpy(yh[i].email,eml); strcpy(yh[i].tele,yhdh);strcpy(yh[i].address,ad);
  }
    i++;
}  
fclose(fp);
   if((fp=fopen("c:\\vc\\a2.txt","w"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
   for(n=0;n<i-1;n++)
    fprintf(fp,"%15s%15s%15s%15s\n",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
   fclose(fp);
}
 
void del(char nam[])                              /*删除信息*/
{
   
    FILE *fp;int i=0,n;
     if((fp=fopen("c:\\vc\\a2.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
     while(! feof(fp))
  {
       fscanf(fp,"%s%s%s%s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
       if(strcmp(nam,yh[i].name)!=0) i++;
  }
     fclose(fp);
    if((fp=fopen("c:\\vc\\a2.txt","w"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
     for(n=0;n< i-1;n++)
      fprintf(fp,"%15s%15s%15s%15s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
      fclose(fp);
}

void sort1()                                      /*排序*/
{    struct yhpx
  {
      char name[20];
      char email[20];
      char tele[20];
      char address[20];
  }yhp[100];
    FILE *fp;
    int i,j,n;
    char s[20];
     if((fp=fopen("c:\\vc\\a2.txt","r"))==NULL)
     {
        printf("不能打开文件\n");
        exit(0);
     }
 while(! feof(fp))
     fscanf(fp,"%s%s%s%s\n",yhp[i].name,yhp[i].email,yhp[i].tele,yhp[i].address);
       fclose(fp);
       n=i;
for  (i=0;i<n-1;i++)
    for(j=0;j<-1-i;j++)
      if(yhp[j].tele<yhp[j+1].tele)
      {
           strcpy(s,yhp[j].name);strcpy(yhp[j].name,yhp[j+1].name);strcpy(yhp[j+1].name,s);
           strcpy(s,yhp[j].email);strcpy(yhp[j].email,yhp[j+1].email);strcpy(yhp[j+1].email,s);
           strcpy(s,yhp[j].tele);strcpy(yhp[j].tele,yhp[j+1].tele);strcpy(yhp[j+1].tele,s);
           strcpy(s,yhp[j].address);strcpy(yhp[j].address,yhp[j+1].address);strcpy(yhp[j+1].address,s);
      }
      if((fp=fopen("c:\\vc\\a2.txt","w"))==NULL)
      {
        printf("不能打开文件\n");
        exit(0);
      }
      j=0;
 while(! feof(fp))
     fprintf(fp,"%15s%15s%15s%15s\n",yhp[j].name,yhp[j].email,yhp[j].tele,yhp[j].address);
       fclose(fp);
}
void print ()                         /*输出数据*/
{
    FILE *fp;
    int i=0,n;
    if((fp=fopen("c:\\vc\\a2.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
while(! feof(fp))
     fscanf(fp,"%s%s%s%s\n",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
       fclose(fp);
n=i;
     for(i=0;i<n;i++)
  {
   printf("%15s%15s%15s%15s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
         printf("\n");
  }
}     

   main()
  {      int  select,sel;
        char nam[20];
         do  
         {
                 printf("==========通讯录管理系统==========\n");
                printf("==================================\n");
                printf("       添加数据 请安1\n");
                printf("       电话查询 请安2\n");
                printf("       数据修改 请安3\n");
                printf("       数据删除 请安4\n");
                printf("       数据排序 请安5\n");
                printf("       数据输出 请安6\n");
                printf("       退出程序 请安0\n");
                printf("==================================\n");
             scanf("%d",&select);
       switch(select)
       {
            case 1: add();break;
            case 2: xxcx(); break;
            case 3: printf("请输入姓名");getchar();
                    gets(nam);edits(nam);break;
            case 4: printf("请输入姓名");getchar();
                    gets(nam);
                    del(nam);break;
            case 5: sort1;break;
            case 6: print();break;
            case 0: exit(0);
       }
     }while(1);
  }
   
搜索更多相关主题的帖子: email 通讯录 include address 管理系统 
2013-10-25 11:31
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:10 
你想干什么?

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-10-25 12:06
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:10 
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
  struct yhxx
  {
      char name[20];
      char email[20];
      char tele[20];
      char address[20];
  }yh[1000];
void add()                               /*添加数据*/
{
     int i,j,n=0; FILE *fp;char ch;
   do
   {  i=n;
   
        printf("请输入第%d条数据:姓名,邮箱,手机,地址\n",n+1);
        scanf("%s%s%s%s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
         n++;
         getchar();
         printf("请继续添加数据(y/n?)");
         ch=getchar();  
   }    while(ch=='y'||ch=='Y');
        if((fp=fopen("F:\\专业课程\\数据测试1.txt","a"))==NULL)
        {
        printf("不能打开文件\n");
        exit(0);
        }
       for(j=0;j<n;j++)
        fprintf(fp,"%15s%15s%15s%15s\n",yh[j].name,yh[j].email,yh[j].tele,yh[j].address);
         fclose(fp);
}


void chaxing(char nam[])     /*按姓名查询:*/
{
    FILE *fp;
    int i=1;
      if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
   {
        printf("不能打开文件\n");
        exit(0);
   }
   do
   {
         fscanf(fp,"%15s%15s%15s%15s\n",&yh[i].name,&yh[i].email,&yh[i].tele,&yh[i].address);
         if(strcmp(nam,yh[i].name)==0)
   {
              puts(yh[i].name);
              puts(yh[i].email);
              puts(yh[i].tele);
               puts(yh[i].address);
              printf("\n");
             break;
   }
   }while(!feof(fp));                       /*是否到文件夹末尾*/
           if(feof(fp))
          printf("查无此人\n");
}

void chaemail(char nam[])                 /*按email查询*/
{  
    FILE *fp;
      int i;
       if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
          i=0;
do
{
         fscanf(fp,"%15s%15s%15s%15s\n",&yh[i].name,&yh[i].email,&yh[i].tele,&yh[i].address);
             if(strcmp(nam,yh[i].email)==0)
    {   
          puts(yh[i].name);
          puts(yh[i].email);
          puts(yh[i].tele);
          puts(yh[i].address);
          printf("\n");break;
    }
} while(!feof(fp));
       if(feof(fp))  printf("查无此人\n");
}

void chashou(char nam[])      /*按手机号查询*/
{     
   FILE *fp; int i;
       if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
       i=0;
       do
    {   fscanf(fp,"%15s%15s%15s%15s\n",&yh[i].name,&yh[i].email,&yh[i].tele,&yh[i].address);
           if(strcmp(nam,yh[i].tele)==0)
     {
               puts(yh[i].name);
               puts(yh[i].email);
               puts(yh[i].tele);
               puts(yh[i].address);
               printf("\n");
                  break;
     }
    }while(!feof(fp));                         /*是否到文件夹末尾*/
      if(feof(fp)) printf("查无此人\n");
}

void xxcx()                                            /*信息查询*/
{              
      char nam[20];
      int sel;
     do
  {  
         printf("----------信息查询----------\n");
         printf("----------------------------\n");
         printf("1:按姓名查询  \n");
         printf("2:按email查询  \n");
         printf("3:按手机查询  \n");
         printf("0:退出        \n");
         printf("  请选择0-3\n"       );
         printf("----------------------------\n");
            scanf("%d",&sel);
            getchar();
          switch(sel)
    {
             case 1: printf("请输入姓名\n");gets(nam);
                     chaxing(nam);break;
             case 2: printf("请输入email\n");gets(nam);
                     chaemail(nam);break;
             case 3: printf("请输入手机\n");gets(nam);
                     chashou(nam);break;
             case 0:   exit(0);
    default:  printf("请输入0-4\n");      
    }
  }while(1);
}
void edits(char nam[])                             /*信息修改*/
{  
FILE *fp;
int i=0,n;
char yhdh[20],yhm[20],eml[20],ad[20];
    printf("输入修改后的姓名、email、电话和地址");
     gets(yhm);
     gets(eml);
     gets(yhdh);
     gets(ad);
    if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
while(!feof(fp))
{   fscanf(fp,"%s%s%s%s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
     if(strcmp(nam,yh[i].name)==0)
  {  strcpy(yh[i].name,yhm);strcpy(yh[i].email,eml); strcpy(yh[i].tele,yhdh);strcpy(yh[i].address,ad);
  }
    i++;
}  
fclose(fp);
   if((fp=fopen("F:\\专业课程\\数据测试1.txt","w"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
   for(n=0;n<i-1;n++)
    fprintf(fp,"%15s%15s%15s%15s\n",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
   fclose(fp);
}

void del(char nam[])                              /*删除信息*/
{
   
    FILE *fp;int i=0,n;
     if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
     while(! feof(fp))
  {
       fscanf(fp,"%s%s%s%s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
       if(strcmp(nam,yh[i].name)!=0) i++;
  }
     fclose(fp);
    if((fp=fopen("F:\\专业课程\\数据测试1.txt","w"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
     for(n=0;n< i-1;n++)
      fprintf(fp,"%15s%15s%15s%15s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
      fclose(fp);
}

void sort1()                                      /*排序*/
{    struct yhpx
  {
      char name[20];
      char email[20];
      char tele[20];
      char address[20];
  }yhp[100];
    FILE *fp;
    int i=0,j,n;
    char s[20];
     if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
     {
        printf("不能打开文件\n");
        exit(0);
     }
while(! feof(fp))
{
    fscanf(fp,"%15s%15s%15s%15s\n",&yhp[i].name,&yhp[i].email,&yhp[i].tele,&yhp[i].address);
}
  fclose(fp);
 n=i;
for  (i=0;i<n-1;i++)
    for(j=0;j<-1-i;j++)
      if(yhp[j].tele<yhp[j+1].tele)
      {
           strcpy(s,yhp[j].name);strcpy(yhp[j].name,yhp[j+1].name);strcpy(yhp[j+1].name,s);
           strcpy(s,yhp[j].email);strcpy(yhp[j].email,yhp[j+1].email);strcpy(yhp[j+1].email,s);
           strcpy(s,yhp[j].tele);strcpy(yhp[j].tele,yhp[j+1].tele);strcpy(yhp[j+1].tele,s);
           strcpy(s,yhp[j].address);strcpy(yhp[j].address,yhp[j+1].address);strcpy(yhp[j+1].address,s);
      }
      if((fp=fopen("F:\\专业课程\\数据测试1.txt","w"))==NULL)
      {
        printf("不能打开文件\n");
        exit(0);
      }
      j=0;
while(! feof(fp))
     fprintf(fp,"%15s%15s%15s%15s\n",yhp[j].name,yhp[j].email,yhp[j].tele,yhp[j].address);
       fclose(fp);
}
void print ()                         /*输出数据*/
{
    FILE *fp;
    int i=0,n;
    if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
    {
        printf("不能打开文件\n");
        exit(0);
    }
while(! feof(fp))
     fscanf(fp,"%s%s%s%s\n",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
       fclose(fp);
n=i;
     for(i=0;i<n;i++)
  {
   printf("%15s%15s%15s%15s",yh[i].name,yh[i].email,yh[i].tele,yh[i].address);
         printf("\n");
  }
}     

   main()
  {      int  select;//,sel;
        char nam[20];
         do  
         {
                 printf("==========通讯录管理系统==========\n");
                printf("==================================\n");
                printf("       添加数据 请安1\n");
                printf("       电话查询 请安2\n");
                printf("       数据修改 请安3\n");
                printf("       数据删除 请安4\n");
                printf("       数据排序 请安5\n");
                printf("       数据输出 请安6\n");
                printf("       退出程序 请安0\n");
                printf("==================================\n");
             scanf("%d",&select);
       switch(select)
       {
            case 1: add();break;
            case 2: xxcx(); break;
            case 3: printf("请输入姓名");getchar();
                    gets(nam);edits(nam);break;
            case 4: printf("请输入姓名");getchar();
                    gets(nam);
                    del(nam);break;
            case 5: sort1;break;
            case 6: print();break;
            case 0: exit(0);
       }
     }while(1);
  }
2013-10-27 00:14
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2013-10-27 00:15
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2013-10-27 00:16
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
[local]1[/local]void chaxing(char nam[])     /*按姓名查询:*/
{
    FILE *fp;
    int i=1;
      if((fp=fopen("F:\\专业课程\\数据测试1.txt","r"))==NULL)
   {
        printf("不能打开文件\n");
        exit(0);
   }
   do
   {
         fscanf(fp,"%15s%15s%15s%15s\n",&yh[i].name,&yh[i].email,&yh[i].tele,&yh[i].address);
         if(strcmp(nam,yh[i].name)==0)
   {
              puts(yh[i].name);
              puts(yh[i].email);
              puts(yh[i].tele);
               puts(yh[i].address);
              printf("\n");
             break;
   }
   }while(!feof(fp));                       /*是否到文件夹末尾*/
           if(feof(fp))
          printf("查无此人\n");
}
红色部分为修改处.(有好几处,有几个函数被这样子改了.)
我也不大懂只是照着书看了看.
数据测试1.txt的截图,为输入文本的数据.
文件路径被我改了,你复制后再改回来行了.
2013-10-27 00:25
快速回复:通讯录管理系统 除了能录入数据 其它功能为什么都用不了
数据加载中...
 
   



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

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