标题:新手求助,为什么这个不能written,还有一些问题不会,大神帮忙
只看楼主
wu747742038
Rank: 1
来 自:广西科技鹿山学院
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-17
 问题点数:0 回复次数:2 
新手求助,为什么这个不能written,还有一些问题不会,大神帮忙
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#define MAX_SIZE 100
struct student
{
    char name[20];
    char tel[20];
    char email[40];
}stu[MAX_SIZE];
int no;
FILE *fp;
int count;

int  load();        /*载入通讯录文件*/
void save();        /*保存所有联系人*/
void insert();            /*新建联系人*/
void browse();           /*浏览联系人*/
void seek();            /*查找联系人*/
void alter();            /*修改联系人*/
void del();               /*删除联系人*/

void main()
{
   
    char m;
    load();
    system("cls");
    printf("\t    **********************通讯录管理**********************\n\n");                 /*显示菜单*/
    printf("\t    ***********************欢迎使用***********************\n");
    printf("\t    *                     0.查询联系人                   *\n");
    printf("\t    *                     1.浏览通讯录                   *\n");
    printf("\t    *                     2.新建联系人                   *\n");
    printf("\t    *                     3.删除联系人(请慎重!)         *\n");
    printf("\t    *                     4.修改联系人                   *\n");
    printf("\t    *                     5.退出                         *\n");
    printf("\t    ***********************谢谢使用***********************\n");
    printf("\t    请输入数字0-5:");                                                         
    scanf("%d",&m);
    switch(m)
    {
       case 0:system("cls");seek();break;
       case 1:system("cls");browse();break;
       case 2:system("cls");insert();break;
       case 3:system("cls");del();break;
       case 4:system("cls");alter();break;
       case 5:exit(0);break;
       default:printf("请在0-5之间选择\n");
    }

}

int load()
{
    if((fp=fopen("savedate.txt","rb"))==NULL)                    /*判断是否已有通讯录*/
    {
        printf("\n\t\t通讯录未建立!\n");
        if((fp=fopen("savedate.txt","wb"))==NULL)
            printf("\n\t\t通讯录建立失败!\n\n");
        else
        {
            printf("\n\t\t正在建立新通讯录,请稍等···");          /*新建通讯录文档*/
            getchar();
            printf("\n\t\t通讯录建立成功\n\n");
            printf("\n\t\t按任意键继续······");
            getchar();
            count=0;
            return count;
        }
    }
    fseek(fp,0,2);                                                      /*获取通讯录成员数目*/
    if(ftell(fp)>0)            
    {
        rewind(fp);
        for(count=0; !feof(fp)&&fread(&stu[count],sizeof(struct student),1,fp); count++);
        return count;
    }
    else
    {
        count=0;
        return count;
    }
}

void save()                                                  /*保存数据*/
{
    int i;
    fp=fopen("savedate.txt","wb");
    for(i=0;i<count;i++)
    {
        fwrite(&stu[i],sizeof(struct student),1,fp);
    }
    fclose(fp);
}

void seek()                                            /*查询联系人*/
{
    int j;
    char name[20];
    fp=fopen("savedate.txt","rb");
    if(count==0)
    {
        printf("\n\n\n\t\t\t通讯录中没有记录,请先新建联系人");
        printf("\n\n\t\t\t按任意键返回······");
        getchar();
        return;
    }
    printf("\n\t\t\t输入查找的姓名:");                //按姓名查找   
    scanf("%s",name);
    for(j=0;!feof(fp);j++)
    {
        fread(&stu[j],sizeof(struct student),1,fp);
        if(strcmp(name,stu[j].name)==0)
        {
            printf("\n\t\t\t**********************\n");
            printf("\n\t\t\t 姓名:%s\n",stu[j].name);
            printf("\n\t\t\t 电话号码:%s\n",stu[j].tel);
            printf("\n\t\t\t 电子邮箱:%s\n",stu[j].email);
            printf("\n\t\t\t**********************\n");
            fclose(fp);
            printf("\n\t\t\t按任意键返回······");
            getchar();
            return;
        }
    }
    printf("\n\t\t\t未找到联系人,请重试\n");
    printf("\n\t\t\t按任意键返回······");
    getchar();
    fclose(fp);
}

void browse()                                         /*浏览联系人*/
{
    int i;
    char name[20];
    fp=fopen("savedate.txt","rb");
    if(count==0)
    if(no!=0)
    {
        printf("\n\n\t联系人为空,请先新建联系人");               /*判断联系人是否为空*/
        getchar();
        return ;
    }
        printf("\n\t\t*************** 以下为通讯录所有信息************");
        for (i=0;i<no;i++)                                          
        {
            printf("\n\n\t\t %d):",i+1);
            printf("\n\t\t 姓 名: %s",stu[i].name);
            printf("\n\t\t 联系电话: %s",stu[i].tel);
            printf("\n\t\t 电子邮箱: %s",stu[i].email);
            return;
        }
}

void insert()                                        /*新建联系人*/
{
    system("cls");
    printf("\t\t******************* 请输入联系人信息*******************\n");
    printf("\t\t请输入名字:");
    scanf("%s,name\n");
    printf("\t\t请输入电话号码:");
    scanf("%d,tell\n");
    printf("\t\t请输入电子邮箱:");
    scanf("%s,email\n");
    printf("信息已保存!");
    count++;
    save();
    printf("\n\t\t是否继续添加联系人?(y/n)");
    if(getchar()=='y')
    {
        system("cls");
        insert();
    }
    return;
}


void del()                                      /*删除联系人*/
{
    int i,j;
    char name[20];
    fp=fopen("savedate.txt","rb");
    if(count==0)
    {
        printf("n\n\t\t未查找到联系人!");
        getchar();
        return;
    }
    printf("\n\t\t输入要删除的联系人!");            
    scanf("%s",name);
    for(i=0;!feof(fp);i++)
    {
        fread(&stu[i],sizeof(struct student),1,fp);
        if(strcmp(name,stu[i].name)==0)
        {
            printf("\n\t\t你要删除的联系人“%s”:",name);
            printf("\n\n\n\n");
            printf("\n\t\t 姓名:%s\n",stu[i].name);
            printf("\n\t\t 电话号码:%s\n",stu[i].tel);
            printf("\n\t\t 电子邮箱:%s\n",stu[i].email);
            printf("\n\t\t 请慎重处理,是否删除(y/n):");
            if(getchar()!='y')
                return;
            for(j=i;j<count-1;j++)
            {
                stu[j]=stu[j+1];
            }
            count--;
            save();
            printf("\n\n\t\t联系人成功删除");
            getchar();
            return;
        }
    }
    printf("\n\t\t\t未找到该联系人,请重新输入正确姓名\n");
    getchar();
}

void alter()                                      /*修改联系人信息*/
{
    int i;
    char name[20];
    fp=fopen("savedate.txt","rb");
    if(count==0)
    {
        printf("\n\n\t\t联系人为空,请先新建联系人");               /*判断联系人是否为空*/
        getchar();
        return;
    }
    printf("\n\t\t\t输入要修改的联系人姓名:");        
    scanf("%s",name);
    for(i=0;!feof(fp);i++)
    {
        fread(&stu[i],sizeof(struct student),1,fp);
        if(strcmp(name,stu[i].name)==0)
        {
            printf("\n\t\t\t修改的联系人“%s”的信息如下:",name);
            printf("\n\t\t\t****************************\n");
            printf("\n\t\t 姓名:%s\n",stu[i].name);
            printf("\n\t\t 电话号码:%d\n",stu[i].tel);
            printf("\n\t\t 电子邮件:%s\n",stu[i].email);
            printf("\n\t\t\t****************************\n");
            printf("\n\t\t\t是否继续修改(y/n)");
            if(getchar()!='y')
                return;

            printf("\t\t请输入修改后的姓名:");
            scanf("%s",stu[i].name);
            printf("\t\t请输入修改后的电话号码:");
            scanf("%s",stu[i].tel);
            printf("\t\t请输入修改后的电子邮件:");
            scanf("%s",stu[i].email);
        }
            system("cls");
            printf("\n\t\t 您的修改结果为:");
            printf("\n\n\n\n\t\t 姓名:%s\n",stu[i].name);
            printf("\n\t\t 电话号码:%s\n",stu[i].tel);
            printf("\n\t\t 电子邮件:%s\n",stu[i].email);
            printf("\n\t\t 确认修改?(y/n)");
            if(getchar()!='y')
                return;
            save();
            fclose(fp);
            getchar();
            return;
    }
    printf("\n\t\t\t未找到联系人,请重新输入姓名!~\n");
    getchar();
    fclose(fp);
}


新人不太会写,求各位大神指点
搜索更多相关主题的帖子: void 通讯录 written include 联系人 
2013-04-17 15:51
wu747742038
Rank: 1
来 自:广西科技鹿山学院
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-17
得分:0 
还有怎么返回菜单,貌似总是不成功
2013-04-17 15:53
wu747742038
Rank: 1
来 自:广西科技鹿山学院
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-17
得分:0 
求解啊啊啊啊
2013-04-18 09:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-404560-1-1.html




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

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