| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 415 人关注过本帖
标题:a problem about Write record to a file using structure
只看楼主 加入收藏
lzm0707
Rank: 2
等 级:论坛游民
帖 子:20
专家分:33
注 册:2012-2-28
结帖率:100%
收藏
 问题点数:0 回复次数:1 
a problem about Write record to a file using structure
//Write record to a file using structure
#include <stdio.h>
#include <conio.h>
void main()
{
    FILE *fp;
    char another='Y';
    struct emp
    {
        char name[40];
        int age;
        float bs;
    };
    struct emp e;
   
    fp=fopen("employee.dat","w");
    if(fp==NULL)
    {
        puts("can not open file");
        exit(1);
    }
    while(another=='Y')
    {
        printf("\nEnter name,age,salary:");
        scanf("%s,%d,%f",e.name,e.age,e.bs);
/*为什么运行时只接受到第一个字符串后面的都没接受到,比如输入mike 33 4000加回车,但每次都是只把第一个mike写进去了,后面的age和salary都没写进去,age一直是-1,salary是一大串数字*/
        fprintf(fp,"%s %d %f",e.name,e.age,e.bs);
        printf("%s %d %f\n",e.name,e.age,e.bs);
        
        printf("Add another record(Y/N)");
        fflush(stdin);
        another=getche();
    }
    fclose(fp);
}
问题在程序注释里,向各位大神们请教了
搜索更多相关主题的帖子: age void structure problem another 
2012-03-15 10:44
lzm0707
Rank: 2
等 级:论坛游民
帖 子:20
专家分:33
注 册:2012-2-28
收藏
得分:0 
我知道哪错了,取地址符忘了加了,怎么还通过编译了,汗
2012-03-15 11:00
快速回复:a problem about Write record to a file using structure
数据加载中...
 
   



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

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