| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 574 人关注过本帖
标题:求助:文件写入时总会少掉几个数据
只看楼主 加入收藏
影随风
Rank: 2
等 级:论坛游民
帖 子:38
专家分:24
注 册:2013-3-14
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:2 
求助:文件写入时总会少掉几个数据
文件写入时,会少掉几个数据,不知道是什么原因,请大家帮帮忙找找看。


#include<stdio.h>
#include<string.h>
struct friends_list
{
 char  name[10],weixin[20],email[30],sex[2],age[8],qq[11],bd[8],tele[14];   
};
void new_friend(struct friends_list frients[]);
int main(void)
{
 int choice,choice1;
 
 char  name[10],weixin[20],email[30],sex[2] ,age[8],qq[11],bd[8],tele[14];
 struct friends_list friends[1000];
 do
 {
  printf("1:新建 2:浏览 3:删除 4:更新  5:查询 0:退出\n ");
  printf("请选择0~5号功能键\n");
  scanf("%d",&choice);
    if(choice>=0 && choice<=5)
     {
        switch(choice)
        {
        case 1:
            new_friend(friends);   
            break;
                 case 0:break;
        }
     }
    else
          printf("输入错误!请输入0~5号功能键!\n");
}while(choice!=0);
 
 printf("感谢您使用本通讯录,欢迎下次使用\n");
   
  return 0;
}
/*新建通讯录*/
void new_friend(struct friends_list friends[],char *name)
{
    struct friends_list f;
    FILE  *fp;
   
    if(Count==1000)
    {
     printf("通讯录已满\n");                        
                                                                                                
    return ;
    }
    else
    {
        printf("请输入新的联系人\n姓名:");
        scanf("%s",f.name);
        printf("年龄:\n");
        scanf("%s",f.age);
        printf("电话:\n");
        scanf("%s",f.tele);
        printf("qq:\n");
        scanf("%s",f.qq);
        printf("微信:\n");
        scanf("%s",f.weixin);
        printf("生日:\n");
        scanf("%s",f.bd);
        printf("电子邮件:\n");
        scanf("%s",f.email);
        printf("性别:\n");
        scanf("%s",f.sex);
        
        if((fp=fopen("f1.txt","a+"))==NULL)
        {
            printf("File open error!\n");
            exit(0);
        }
        fprintf(fp,"%s %s %s %s %s %s %s %s",f.name,f.age,f.tele,f.qq,f.weixin,f.bd,f.email,f.sex);
        if(fclose(fp))
        {
            printf("Can not close the file !\n");
            exit(0);
        }
    }
     Count++;
}
搜索更多相关主题的帖子: name void friends include choice 
2013-05-13 23:07
猫小喵
Rank: 2
来 自:计算机专业
等 级:论坛游民
帖 子:29
专家分:77
注 册:2013-5-12
收藏
得分:20 
void new_friend(struct friends_list frients[]);与void new_friend(struct friends_list friends[],char *name) 没发现差一个char* name,我没明白你为啥要传指针?也不需要计数还有如果传指针调用函数的实参要写&name,并且在主函数中声明一个字符变量name,还有在你void new_friend(struct friends_list friends[],char *name)中使用了Count作为数据计数,但是你没声明,你说的问题保存我看见是八个数据,

做一个爱编程得女生
2013-05-14 12:16
影随风
Rank: 2
等 级:论坛游民
帖 子:38
专家分:24
注 册:2013-3-14
收藏
得分:0 
回复 楼主 影随风
谢谢了!
2013-05-14 12:43
快速回复:求助:文件写入时总会少掉几个数据
数据加载中...
 
   



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

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