为什么显示文件中的错误信息

时间:2014-03-31 04:50:04

标签: c file struct scanf fseek

我希望我的程序从文件中捕获一定数量的数据(确切地说是最后10条记录)所以我有一个存储以下内容的文本文件。

`文件创建日期:2014年3月30日20:44:05

1000存款:100.00 Sun Mar 30 20:45:02 2014`

这是我目前拥有的以下代码:

typedef struct transaction
{
    int acc_Id;
    char *time;
    char *type;
    float amount;
}my_Trans;

int Dtl(Acc *user)// the user parameter is not used in the code as yet
{
    my_Trans dtl_log[10];// to store the 10 information of my trans 
    FILE *dtl_fp;
    int dtl_Cnd=1,x=0;

    dtl_fp = Opnfile(acclg,r,dnt_ret_fp);// all this does is return my file for reading

    while(dtl_Cnd)
    {
        fseek(dtl_fp,(sizeof(my_Trans))*(-1),SEEK_END);// I set my file cur to the end and start seeking trans size record;
        fscanf(dtl_fp,"%d%s%.2f%s",&dtl_log[x].acc_Id,&dtl_log[x].type,&dtl_log[x].amount,&dtl_log[x].time);// read my trans records and store in my log ready to be displayed the x is just for test purposes to make sure i am getting the correct information out first 
        printf("%d",dtl_log[x].acc_Id);//check my information if it is the right thing
        break;
    }

}

0 个答案:

没有答案