我想知道哪错了,为什么从文件读出不了money

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
struct bank{
  int id;
  char name[30];
  double money;
  };
int main(){
  struct bank *p,*q;
  p=(struct bank*)malloc(sizeof(struct bank));
  q=(struct bank*)malloc(sizeof(struct bank));
  FILE *fp;
  p->id=20;
  p->money=50;
  if((fp=fopen("ddh.txt","w+"))==NULL)
  {
      printf("cuowu");
      exit(0);
  }
  fprintf(fp,"%d,%f",p->id,p->money);
  fclose(fp);
  fp=fopen("ddh.txt","r");
    if(!fp)
    {
        printf("errror!\n");
        exit(-1);
    }
    fscanf(fp,"%d,%f",&q->id,&q->money);
    fclose(fp);
    printf("%d,%f",q->id,q->money);
  }

猜你喜欢

转载自blog.csdn.net/qq_42619102/article/details/80930558