| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1296 人关注过本帖
标题:这个代码哪儿有问题,求大神帮忙
只看楼主 加入收藏
和过去说拜拜
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-9-24
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
这个代码哪儿有问题,求大神帮忙
#include<stdio.h>
#include<string.h>
#include<windows.h>

typedef struct Man{
    char Name[12];
    char Sex[4];
    char Old[4];
    char Mobil[12];
    char Tel[12];
    char Address[16];
    char QQ[12];
    char Email[16];
    char Sort[12];
}man;
 
void TianJia( FILE *fp);
void XiuGai( FILE *fp);
void ShanChu( FILE *fp);
void ChaXun( FILE *fp);
void XianShi( FILE *fp);

int jishu(char *p);
int main()
{
    system("color 51");
    char b,c;
    FILE *fp;

do{
    printf("\t\t☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★\n");
    printf("\t\t★              通 讯 录              ☆\n");
    printf("\t\t☆   1、添加信息       2、查询信息    ★\n");
    printf("\t\t★                                    ☆\n");
    printf("\t\t☆   3、删除信息       4、修改信息    ★\n");
    printf("\t\t★                                    ☆\n");
    printf("\t\t☆   5、显示信息       6、退出程序    ★\n");
    printf("\t\t★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆\n");

    printf("请选择您想要执行操作的代码: ");
    scanf("%d",&c);
    printf("\n");   
    switch ( c )
    {
    case 1:
        fp = fopen("d:\\tongxunlu.txt","ab+");
        TianJia( fp);
        break;
    case 2:
        fp = fopen("d:\\tongxunlu.txt","rb");
        ChaXun( fp);
        break;
    case 3:
        fp = fopen("d:\\tongxunlu.txt","rb+");
        ShanChu( fp);
        break;
    case 4:
        fp=fopen("d:\\tongxunlu.txt","rb+");
        XiuGai( fp);
        break;
    case 5:
        fp=fopen("d:\\tongxunlu.txt","rb");
        XianShi( fp);
        break;
    case 6:
        printf("谢谢使用!\n");
        exit(0);
    default:
        printf("输入有误,请重新输入!\n");
        break;
    }

        fflush( stdin);
        fclose(fp);        
     
        printf("请入y继续其他功能\n");
        scanf("%c",&b);
        if(b=='y')
        {           system("cls");
        }
}while(c != 6);
      return 0;
}
void TianJia( FILE *fp)
{    man a1;
    printf("请输入您要添加的人员信息\n");
    rewind( fp);
           printf("\n");
           printf("姓名:");
              scanf("%s",&a1.Name);
           fflush(stdin);
      
              printf("\n");
           printf("性别:");
           scanf("%s",&a1.Sex);
           fflush(stdin);

           printf("\n");
           printf("年龄:");
           scanf("%s",&a1.Old);
           fflush(stdin);

           printf("\n");
           printf("移动电话:");
           scanf("%s",&a1.Mobil);
           fflush(stdin);

           printf("\n");
           printf("固定电话:");
           scanf("%s",&a1.Tel);
           fflush(stdin);

           printf("\n");
           printf("住址:");
           scanf("%s",&a1.Address);
           fflush(stdin);

           printf("\n");
           printf("QQ:");
           scanf("%s",&a1.QQ);
           fflush(stdin);

           printf("\n");
           printf("Email:");
           scanf("%s",a1.Email);
           fflush(stdin);

           printf("\n");
           printf("类别:");
           scanf("%s",a1.Sort);
           fflush(stdin);
        

           fp = fopen("d:\\tongxunlu.txt","a+");         
           fwrite(&a1,sizeof( a1),1,fp);         
     

     fclose( fp);
}

void ChaXun( FILE *fp)
{     man a2;
     char name1[12];   

     printf("请输入你要查找的人员姓名:");
     scanf("%s",name1);
     fflush( stdin);
     rewind(fp);
         while( fread( &a2, sizeof( a2), 1, fp)!= NULL)
         {        
              if( strcmp( name1, a2.Name) == 0)
              {
                  printf("您所查询的人员信息如下:\n");
                  printf("姓名:%s\n\n性别:%s\n\n年龄:%s\n\n住址:%s\n\n移动电话:%s\n\n固定电话:%s\n\nQQ:%s\n\nEmail:%s\n\n类别:%s\n",
                  a2.Name, a2.Sex, a2.Old, a2.Address, a2.Mobil,a2.Tel, a2.QQ, a2.Email, a2.Sort);

              }

              else
              {
                  printf("您要查询的人员资料不存在!\n");
                  

              }
         }


     fclose( fp);
     return;

}

void XiuGai( FILE *fp)
{

    man a3;
    man one;
    int count1 = 0;
    char name2[12];


       printf("请输入您要修改的人员姓名:");
       scanf("%s", &name2);
       fflush( stdin);

      while( !feof( fp))
      {
         fread( &a3,sizeof( a3), 1, fp);
         count1++;

        if( strcmp( name2,a3.Name) ==0)
        {
                printf("姓名:%s\n性别:%s\n年龄:%s\n住址:%s\n移动电话:%s\n固定电话:%s\nQQ:%s\nEmail:%s\n类别:%s\n",
                 a3.Name, a3.Sex, a3.Old, a3.Address, a3.Mobil, a3.Tel, a3.QQ, a3.Email, a3.Sort);

                printf("请输入您要修改的资料.\n");
                printf("\n");
                printf("姓名:");
                   scanf("%s",&one.Name);
                fflush(stdin);
      
                   printf("\n");
                printf("性别:");
                scanf("%s",&one.Sex);
                fflush(stdin);

                printf("\n");
                printf("年龄:");
                scanf("%s",&one.Old);
                fflush(stdin);

                printf("\n");
                printf("移动电话:");
                scanf("%s",&one.Mobil);
                fflush(stdin);

                printf("\n");
                printf("固定电话:");
                scanf("%s",&one.Tel);
                fflush(stdin);

                printf("\n");
                printf("住址:");
                scanf("%s",&one.Address);
                fflush(stdin);

                printf("\n");
                printf("QQ:");
                scanf("%s",&one.QQ);
                fflush(stdin);

                printf("\n");
                printf("Email:");
                scanf("%s",&one.Email);
                fflush(stdin);

                printf("\n");
                printf("类别:");
                scanf("%s",&one.Sort);
                fflush(stdin);

                fseek(fp,(count1 - 1)*sizeof( a3),SEEK_SET);
                fwrite(&one,sizeof( one),1,fp);            
 
                printf("修改成功!\n");
                return;
}
Else
            {
                printf("您要修改的人员不存在!\n");               
                return;
            }
      }

     fclose( fp);
     return;   
}  

    void ShanChu( FILE *fp)
{   
       man a4;
       man blank = {0};
       char name3[12];
       int count = 0;
       rewind(fp);
       printf("请输入您要删除的人员姓名:");
       scanf("%s",&name3);
       fflush( stdin);
       while( !feof( fp))
       {
           fread( &a4,sizeof( a4), 1, fp);
           count++;

           if( strcmp( name3,a4.Name) ==0)
           {
                 printf("姓名:%s\n性别:%s\n年龄:%s\n住址:%s\n移动电话:%s\n固定电话:%s\nQQ:%s\nEmail:%s\n类别:%s\n",
                 a4.Name, a4.Sex, a4.Old, a4.Address, a4.Mobil, a4.Tel, a4.QQ, a4.Email, a4.Sort);

                 fseek( fp,( count - 1) * sizeof( a4), SEEK_SET);
                 fwrite( &blank, sizeof( blank), 1, fp);
                 printf("删除成功!");
                 fclose( fp);
                 return;
           }
          else
          {
            printf("您要删除的人员不存在!\n");
            return;
          }
          fclose( fp);
          return;
       }
}
void XianShi( FILE *fp)
{
    char m = 0, n;
    man a5;

  while( !feof( fp))
  {
        fread( &a5,sizeof( a5), 1, fp);
        m++;      
  }   
     for( n = 0; n < m -1; n++ )
     {   
         fread( &a5, sizeof( a5), 1, fp);
         printf("您所需要的资料如下:\n");
         printf("姓名:%s\n性别:%s\n年龄:%s\n住址:%s\n移动电话:%s\n固定电话:%s\nQQ:%s\nEmail:%s\n类别:%s\n",
                 a5.Name, a5.Sex, a5.Old, a5.Address, a5.Mobil, a5.Tel, a5.QQ, a5.Email, a5.Sort);
     }
         fclose( fp);  
}
搜索更多相关主题的帖子: include system Email color 
2016-09-24 21:47
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
收藏
得分:10 
是不是应该先自己仔细看看,标注下自己认为有问题的地方

人有多懒,编程就有多难。
2016-09-24 22:32
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:10 
这个代码存在什么问题讲清楚来
2016-09-25 01:26
快速回复:这个代码哪儿有问题,求大神帮忙
数据加载中...
 
   



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

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