| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 328 人关注过本帖
标题:求帮忙看看通讯录代码哪儿错了 顺便帮忙写下删除函数的代码
只看楼主 加入收藏
tianxintong
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-3-30
结帖率:50%
收藏
 问题点数:0 回复次数:1 
求帮忙看看通讯录代码哪儿错了 顺便帮忙写下删除函数的代码
#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\t tong xun lu");
    printf("----------------------------------");
    printf("1liulan");
    printf("2tianjia");
    printf("3xiugai");
       printf("4chazhao");
       printf("5shanchu");
       printf("6tuichu");
       printf("\n--------------------------------");
       printf("wo yao xuan ze:");
       scanf("%d",&i);return i;
}
tj()
{
    int a;
    struct xx ;
    FILE *fp
    if((fp=fopen("xinxi.txt"),"wb")==NULL)
{
    printf("error....\n");
    getch();
    main();
}
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 email:");
gets(xx.email);
fclose(fp);
printf("\n1.fanhui--2.tianjia--3.tuichu");
scanf("%d",&a);
if(a==1)
{
     main();
}
else if(a==2)
     {
          tj();
     }
     else if(a==3)
          {
              exit(0);
          }
          else
          {
              printf("error");
              getch();
            main();
          }
}
xs()
{
    int i;
    struct xx ;
    FILE *fp
    if((fp=fopen("xinxi.txt"),"rb")==NULL)
{
    printf("error....\n");
    getch();
    main();
}
     while(fread(&xx,sizeof(xx),1,fp)==1)
     {
         printf("xingming:%s\n",xx.xingming);
         printf("xingbie:%s\n",xx.xingbie);
         printf("dianhuo:%s\n",xx.dianhua);
         printf("qq:%s\n",xx.qq);
         printf("email:%s\n",xx.email);
     }
     fclose(fp);
     printf("1.fanhui  2.tuichu");
     scanf("%d",&i);
     if(i==1)
     {
         main();
     }
     else if(i==2)
     {
         exit(0);
     }
          else
          {
              getch();
              clrscr();
              xs();
          }
}
xg()
{
    struct xx;
    FILE *fp1,fp2;
    int flag;
    char name;
    int a;
    if((fp1=fopen("xinxi.txt"),"wb")==NULL)
{
    printf("error....\n");
    getch();
    main();}
    if((fp2=fopen("temp.txt"),"wb")==NULL)
{
    printf("error....\n");
    getch();
    main();}
    printf("shu ru name:");
    scanf("%s",&name);
    flag=0;
    while(fread(&xx.sizeof(xx),1,fp1)==1)
    {
            if(strcmp(name,xx.xingming)==0)
        {
            printf("xingming:%s\n",xx.xingming);
         printf("xingbie:%s\n",xx.xingbie);
         printf("dianhuo:%s\n",xx.dianhua);
         printf("qq:%s\n",xx.qq);
         printf("email:%s\n",xx.email);
         printf("shu ru xin nei rong:");
         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 email:");
        gets(xx.email);
         flag=1;
        }
         fwrite(&xx,sizeof(xx),1,fp2);
    }
    fclose(fp1);
    fclose(fp2);
    if(flag==1)
    {
        printf("sucess");
        remove("xinxi.txt");
        rename("temp.txt","xinxi.txt");
    }
    else printf("error");
    getch();
    printf("1.jixu 2.fanhui 3.tuichu");
    scanf("%d",&b);
    if(a==1)
    {
        clrscr();
        xg();
    }
    else if(a==2)
    {
         main();
    }
        else if(a==3)
            {
                exit(0)
            }
            else printf("error");
            clrscr();
        xg();
   
        
   
}
cx()
{
    struct xx;
    FILE *fp;
    int flag;
    int total;
    char ch;
    int b,tel;
    if((fp=fopen("xinxi.txt"),"ab")==NULL)
{
    printf("error....\n");
    getch();
    main();}
    rewind(fp);
    printf("1.name 2.tel");
    scanf("%d",&flag);
    if(flag==1)
    {
        printf("shu ru xing ming");
        scanf("%s",&ch);
        total=0;
        while(fread(&xx.sizeof(xx),1,fp)==1)
        if(strcmp(ch,xx.xingming)==1)
        {
            total++;
            if(total==1)
            printf("xingming xingbie dainhua qq email",%sxx.xingming%sxx.xingbie%sxx.dianhua%sxx.qq%sxx.email);
        }
    }
    if(flag==2)
    {
        printf("shu ru dianhua:");
        scanf("%s",&tel);
        total=0;
        while(fread(&xx.sizeof(xx),1,fp)==1)
        if(strcmp(tel,xx.dianhua)==0)
        {
            total++;
            if(total==1)
            printf("xingming xingbie dainhua qq email",%sxx.xingming%sxx.xingbie%sxx.dianhua%sxx.qq%sxx.email);
        }
    }
    fclose(fp);
    printf("1.fanhui 2.tuichu");
    scanf("%d",&b);
    if(b==1)
    {
        main();
    }
    else
    {
        exit(0);
    }
}
sc()
{
   
}

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();sc();break;
    case 6:exit(0);break;
}
搜索更多相关主题的帖子: 通讯录 email 
2011-04-02 11:56
hnuhsg1226
Rank: 9Rank: 9Rank: 9
来 自:中国
等 级:蜘蛛侠
威 望:2
帖 子:314
专家分:1314
注 册:2011-3-27
收藏
得分:0 
写法好不规范,我弄了个简单通讯录,没有链表操作的,你自己对比下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 10

void init(void);/*结构初始化*/
int hello(void);/*系统界面*/
void enter(void);/*录入通讯信息*/
void scan(void); /*浏览通讯信息*/
void inquiry(void);/*查询通讯信息*/
void modify(void);/*修改通讯信息*/
void del(void);/*删除某个通讯信息*/
int find_free(void);/*检测通讯录里是否有空栏*/

struct addr{      /*通讯录结构体*/
    char name[30];/*姓名*/
    char phone[30];/*电话*/
    char email[30];/*电子邮箱地址*/
}address[MAX];

int main()
{
    int p;
    init();
    for(;;)
    {
        p=hello();
        switch(p){
            case 1:enter();break;
            case 2:scan();break;
            case 3:inquiry();break;
            case 4:modify();break;
            case 5:del();break;
            case 6:exit(0);
        }
    }
    return 0;
}

void init()
{
    register int t;
    for(t=0;t<MAX;t++)
        address[t].name[0]='\0';
}

int hello()
{
    char a[10];
    int b;
    printf("\n***************欢迎登陆通讯录系统**************\n");
    printf("1.信息录入;\n");
    printf("2.信息浏览;\n");
    printf("3.信息查询;\n");
    printf("4.信息修改;\n");
    printf("5.信息删除;\n");
    printf("6.退出系统;\n");
    printf("***********************************************\n");
    printf("请输入你需要的服务:");
    do
    {
        printf("你输入有误,请重新输入:");
        gets(a);
        b=atoi(a);
    }while(b<0||b>6);
    return b;
}

void enter()
{
    int p;
    p=find_free();
    if(p==MAX)
    {
        printf("\n信息储存已满,需要删除其他的,才能执行录入操作\n");
        return;
    }
    printf("请输入姓名:");
    gets(address[p].name);
    printf("电话号码:");
    gets(address[p].phone);
    printf("电子邮箱:");
    gets(address[p].email);
}

int find_free()
{
    register int i;
    for(i=0;address[i].name[0]&&i<MAX;i++)
    if(i==MAX)  return MAX;
    return i;
}

void scan()
{
    register int j;
    for(j=0;j<MAX;j++)
    {
        if(address[j].name[0])
        {
            printf("%s   %s   %s\n",address[j].name,address[j].phone,address[j].email);
        }
    }
    printf("\n\n");
}

void inquiry()
{
    char s[30];
    int p,i;
    printf("请输入需要查找的姓名:");
    gets(s);
    for(i=0;i<MAX;i++)
    {
        p=strcmp(s,address[i].name);
        if(!p)
        {
            printf("%s   %s   %s\n",address[i].name,address[i].phone,address[i].email);
        }
    }
    if(i==MAX)
    {
        printf("找不到你输入的姓名\n");
    }
}

void modify()
{
    int p,i;
    char s[30];
    printf("请输入你需要修改的人的姓名:");
    gets(s);
    for(i=0;i<MAX;i++)
    {   
        p=strcmp(s,address[i].name);
        if(!p)
        {
            int j;
            char m[10];
            printf("******************************\n");
            printf("1.姓名\n");
            printf("2.电话号码\n");
            printf("3.电子邮箱\n");
            printf("******************************\n");
            printf("请输入你要修改的选项:");
            do
            {
                gets(m);
                j=atoi(m);
            }while(j<1||j>3);
            switch(j)
            {
            case 1:    printf("请输入姓名:");
                    gets(address[i].name);
                    break;
            case 2: printf("电话号码:");
                    gets(address[i].phone);
                    break;
            case 3: printf("电子邮箱:");
                    gets(address[i].email);
                    break;
            }
        }
    }
    if(i==MAX)
    {
        printf("没有你修改人的信息.\n");
    }
}

void del()
{
    int p,i;
    char s[30];
    printf("请输入所删除人的姓名:");
    gets(s);
    for(i=0;i<MAX;i++)
    {
        p=strcmp(s,address[i].name);
        if(!p)
        {
            address[i].name[0]='\0';
        }
    }
    if(i==MAX)
    {
        printf("没有你删除人的信息.\n");
    }
}

我的地盘
2011-04-02 18:18
快速回复:求帮忙看看通讯录代码哪儿错了 顺便帮忙写下删除函数的代码
数据加载中...
 
   



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

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