当前位置:编程学习 > VC++ >>

vc++ 批量读取和存储文件

%循环读取和存储dat文件: 

for (int i1=1; i1<=20; i1++) 
 
for (int j1=1; j1<=4;j1++) 

 char readfile[15]; 
 sprintf_s(readfile, "d%dc%d.dat", i1,j1); 
 read_data(readfile,WrappedImage,volume_size); 
 char writefile[15]; 
 sprintf_s(writefile, "und%dc%d.dat", i1,j1); 
 write_data(writefile,WrappedImage,volume_size); 
 

%读取dat文件


void read_data(char *inputfile,float *Data, int length) 

 printf("Reading the Wrapped Values form Binary File.............>"); 
 FILE *ifptr; 
 ifptr = fopen(inputfile,"rb"); 
 if(ifptr == NULL) printf("Error opening the file\n"); 
 fread(Data,sizeof(float),length,ifptr); 
 fclose(ifptr); 
 printf(" Done.\n"); 

%保存dat文件


void write_data(char *outputfile,float *Data,int length) 

 printf("Writing the Unwrapped Values to Binary File.............>"); 
 FILE *ifptr; 
 ifptr = fopen(outputfile,"wb"); 
 if(ifptr == NULL) printf("Error opening the file\n"); 
 fwrite(Data,sizeof(float),length,ifptr); 
 fclose(ifptr); 
 printf(" Done.\n"); 

摘自 myj0513的专栏

补充:软件开发 , Vc ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,