| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2043 人关注过本帖
标题:做得通讯录,有些错误,大家帮忙纠正下!Win-tc编译环境
取消只看楼主 加入收藏
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
结帖率:50%
收藏
 问题点数:0 回复次数:4 
做得通讯录,有些错误,大家帮忙纠正下!Win-tc编译环境
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
struct xx
{
   char xingming[15];
   char xingbie[5];
   char dianhua[13];
   char qq[13];
   char email[30];
};
int printf1()                              /*菜单函数*/
{
   int i;
   clrscr();
   printf("\t\t\t\tTong Xun Lu\n");
   printf("--------------------------------------------------------------------------------");
   printf("1.Liu Lan    ");
   printf("2.Tian Jia    ");
   printf("3.Xiu Gai    ");
   printf("4.Cha Zhao    ");
   printf("5.Shan Chu    ");
   printf("6.Tui Chu");
   printf("\n--------------------------------------------------------------------------------");
   printf("Wo Yao Xuan Ze:");
   scanf("%d",&i);
   return i;
}
tj()                                       /*添加函数*/
{
   int a;
   struct xx XX;
   FILE *fp;
   if((fp=fopen("xinxi.txt","ab"))==NULL)
   {
     printf("Error....Can't nofind the file!\n");
     getch();
     return main();
     }
   printf("Shu Ru Xing Ming:");
   gets(XX.xingming);
   clrscr();
//不好意思,没办法描述,删除红色代码在试试看。这个问题很奇怪
   printf("Shu Ru Xing Ming:");
   gets(XX.xingming);
   printf("Shu Ru Xing Bie:");
   gets(XX.xingbie);
   printf("Shu Ru Dian Hua:");
   gets(XX.dianhua);
   printf("Shu Ru QQ:");
   gets(XX.qq);
   printf("Shu Ru E-mail:");
   gets(XX.email);
   fwrite(&XX,sizeof(XX),1,fp);
   fclose(fp);
   printf("\n1.Fanhui--2.Tianjia--3.Tuichu-->[ ]\b\b");
   scanf("%d",&a);

   if(a==1)
   {
     return main();
     }
     else if(a==2)
     {
   return tj();
   }
   else if(a==3)
   {
      exit(0);
      }
   else
   {
    printf("Error!Please cry again!\n");
    getch();
    return main();
    }
   }
xs()     显示正常,但生成的txt文件里有乱码出现     /*显示函数*/
{
    FILE *fp;
    int i;
    struct xx XX;
    if((fp=fopen("xinxi.txt","rb"))==NULL)
      {
        printf("Error....Can't nofind the file!");
        getch();
        main();
        }
     while(fread(&XX,sizeof(XX),1,fp)==1)
       {
          printf("Xingming: %s\n",XX.xingming);
          printf("Xingbie : %s\n",XX.xingbie);
          printf("Dianhua : %s\n",XX.dianhua);
          printf("QQ      : %s\n",XX.qq);
          printf("E-mail  : %s\n\n",XX.email);
          }
     fclose(fp);
     printf("(1.fanhui||2.tuichu)-->[ ]\b\b");
     scanf("%d",&i);
     if(i==1)
     {
        return main();
        }
        else if(i==2)
        {
          exit(1);
          }
          else
          printf("Error....Please input 1 or 2!");
          getch();
          clrscr();
          xs();
     }
cx() 这段函数代码不知道哪里错误了,编译通过,但运行起来不是我想要的功能      /*查询函数*/
{
    struct xx XX;
    FILE *fp;
    int flag;
    int total;
    char ch;
    int b;
    int tel;
    if((fp=fopen("xinxi.txt","rb"))==NULL)
      {
         printf("Error....Can't find the file!");
         getch();
         main();
         }
      rewind(fp);
      clrscr();
      printf("( 1.Name || 2.Tel || 3.Fanhui )---->[ ]\b\b");
      scanf("%d",&flag);
      if(flag==1)                  /*按姓名查询*/
      {
        printf("Please input the name you want to search:");
        scanf("%s",&ch);
        total=0;
        while(fread(&XX,sizeof(XX),1,fp)==1)
           if(strcmp(ch,XX.xingming)==1)
             {
               total++;
               if(total==1)
               printf("\nXing Ming:%s\nXing Bie:%s",XX.xingming,XX.xingbie);
               }
               else
               printf("\nSorry!Can't find the poper!\n\n");
               getch();
               }
       else if(flag==2)                  /*按电话查询*/
         {
           printf("Please input tel you want to search:");
           scanf("%s",&tel);
           total=0;
           while(fread(&XX,sizeof(XX),1,fp)==1)
             if(strcmp(tel,XX.dianhua)==0)
             {
               total++;
               if(total==1)
               printf("\nXing Ming:%s\nXing Bie:%s",XX.xingming,XX.xingbie);
               }
               else
               printf("\nSorry!Can't find the poper!\n\n");
               getch();
               }
               else
               {
                  main();
                  }
               fclose(fp);
               printf("1.Jixu||2.Fanhui||3.Tuichu-->[ ]\b\b");
               scanf("%d",&b);
               if(b==1)
               {
                 cx();
                 }
                 else if(b==2)
                 {
                 main();
                 }
                 else
                 {
                    exit(1);
                    }
                 }
xg()   修改函数也是。。。       /*修改函数*/
{
   struct xx XX;
   FILE *fp1,*fp2;
   int flag;
   char name;
   int a;
   if((fp1=fopen("xinxi.txt","rb"))==NULL)
   {
        printf("Error....Can't nofind the file!");
        getch();
        main();
        }
    if((fp2=fopen("temp.txt","wb"))==NULL)
    {
       printf("Error....Can't nofind the file!");
        getch();
        main();
        }
        printf("Please input the name you want to modify:");
        scanf("%s",&name);
        flag=0;
        while(fread(&XX,sizeof(XX),1,fp1)==1)
        {
          if(strcmp(name,XX.xingming)==0)
          {
            printf("\nXingming:%s\n",XX.xingming);
            printf("Xingming  :%s\n",XX.xingbie);
            printf("Xingming  :%s\n",XX.dianhua);
            printf("Xingming  :%s\n",XX.qq);
            printf("Xingming  :%s",XX.email);
            printf("\n\n\nShu Ru Xin Ji Lu\n");
            printf("Xingming:");
            gets(XX.xingming);
            printf("Xingbie:");
            gets(XX.xingbie);
            printf("Dianhua:");
            gets(XX.dianhua);
            printf("QQ:");
            gets(XX.qq);
            printf("E-mail:");
            gets(XX.email);
            flag=1;
            }
            fwrite(&XX,sizeof(XX),1,fp2);
            }
            fclose(fp1);
            fclose(fp2);
            if(flag==1)
            {
              printf("Modify sucess!\n");
              remove("xinxi.txt");
              rename("temp.txt","xinxi.txt");
              }
              else
              printf("Can't find this recore!\n");
              getch();
              printf("1.Jixu||2.Fanhui||3.Tuichu-->[ ]\b\b");
              scanf("%d",&a);
              if(a==1)
              {
              clrscr();
              xg();
              }
              else if(a==2)
              {
                 main();
                 }
                 else if(a==3)
                 {
                   exit(0);
                   }
                   else
                   printf("Please input 1,2,3!OK?");
                   getch();
                   clrscr();
                   xg();
              }
sc()    删除函数的思路是怎么样的
{
   struct xx XX;
   FILE fp1,fp2;
   char name;
   int flag;
   if((fp1=fopen("xinxi.txt","rb"))=NULL)
     {
        printf("Can't open the file!");
        getch();
        main();
        }
   if((fp1=fopen("temp.txt","wb"))=NULL)
     {
        printf("Can't open the file!");
        getch();
        main();
        }
        printf("Please input name:");
        gets(name);
        flag=0;
    while(fread(&XX,sizeof(XX),1,fp1)==1)
    {
      if(strcmp(name,XX.xingming)==0)
       {
         printf("Xingming:%s\nXingbie:%s\nDianhua:%s");
         flag=1;






main()
{
   switch(printf1())
   {
     case 1:clrscr();xs();break;
     case 2:clrscr();tj();break;
     case 3:clrscr();xg();break;
     case 4:clrscr();cx();break;
     case 5:clrscr();printf("Deng Dai!");getch();main();break;
     case 6:exit(0);break;
     default:clrscr();printf("Error.....Please cry again!");getch();main();break;
     }
          }
搜索更多相关主题的帖子: 通讯录 编译 printf 环境 include 
2008-07-18 00:20
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
收藏
得分:0 
没人帮帮偶????
2008-07-19 21:43
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
收藏
得分:0 
恩,谢谢你,不过为什么
getchar();   /*用来接收'\n'*/
我就郁闷这一点,因为我没有getchar(),输出的时候,姓名和性别就是显示为一行
为什么呢??
2008-07-22 07:34
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
收藏
得分:0 
我们学的教科书怎么就没有「堆栽」这一类的词啊?
2008-07-29 02:49
maiiho
Rank: 1
等 级:新手上路
帖 子:94
专家分:7
注 册:2008-7-17
收藏
得分:0 
堆栈是怎么样的一个概念?
学校发的C课程好象对此没有介绍啊
堆栈是怎么样的概念?
2008-07-31 21:12
快速回复:做得通讯录,有些错误,大家帮忙纠正下!Win-tc编译环境
数据加载中...
 
   



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

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