标题: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



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




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

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