文件读取,请帮忙修改
程序代码:
#include<stdio.h> int main(void) { int account; char name[30]; double balance; FILE *cfPtr; if((cfPtr=fopen("clients.dat","r"))==NULL) { printf("Files not exist!"); } else { printf("%-10s%-13s%s\n", "ACCOUNT","NAME","BALANCE"); fscanf(cfPtr,"%d%s%lf",&account, name, &balance); while(!feof(cfPtr)) { printf("%-10d%-13s%7.2f\n", account,name,balance); fscanf(cfPtr,"%d%s%lf",&account, name, &balance); } fclose(cfPtr); } return 0; }
数据如下:
程序代码:
100Jones24.98 200Doe345.67 300White0.00 400White-42.16 500Rich224.62