#include<stdio.h>
#include<string.h>
#include <io.h>
#include<stdlib.h>
#define MAX_LINE 11
#define ALL_TIME 200
const char *to_search="C:\\Users\\admin\\Desktop\\Glu算法\\*.txt"; //欲查找的文件,支持通配符
FILE *fp;
FILE *fp2;
int main()
{
system("color f1");
//printf("请输入想得到最后x秒内的时间电流数据(/s):\n形式如:50\n");
char buf[MAX_LINE]; /*缓冲区*/
int t1;
scanf("%d",&t1);
int n=0;//已经处理的文件数量
//char newname[20]={0} ;
//char prefix[10]="MIT_" ;
long handle; //用于查找的句柄
struct _finddata_t fileinfo; //文件信息的结构体
fp = fopen("C:\\Users\\admin\\Desktop\\Glu浓度算法\\ZCY.txt", "w+");//新建一个txt文件: ZCY-info.txt
if (fp==0)
{
printf("can't open file\n");
return 0;
}
handle=_findfirst(to_search,&fileinfo); //第一次查找
if(-1==handle)
return -1;
//printf("concentration/mMCurrunt(aver%ds-%ds)/uA\n",t1,t2);
//int c=getnd(fileinfo.name);
//printf("%d",c);
if((fp2 = fopen(fileinfo.name,"r"))==NULL)
{
perror("fail to read");
exit (1) ;
}
int m=0;
int k=0;
float temp_t=0;//时间
float current=0;
int g=0;
while(fgets(buf,MAX_LINE,fp2)!= NULL)
{
if(m%2==0)
{
temp_t=atof(buf);
//printf("temp_t=%f\n",temp_t);
if(temp_t>ALL_TIME-t1)
k=1;
}
if(k==1&&buf!=NULL)
{
if(m%2==0)
{
temp_t=temp_t-ALL_TIME+t1+n*t1;
fprintf(fp,"%f, ",temp_t);//写入时间数据
}
if(m%2==1)
{
fprintf(fp,"%s",buf);//写入电流数据
}
}
m++;
}
//printf("%f\n",aver/n);
//fprintf(fp,"%d",c); //打印出信息
//fprintf(fp,"%f\n",aver/n); //打印出信息
//printf("k=%d\n",k);
//printf("Hello World\n");
//sprintf(newname,"%s%s",prefix,fileinfo.name);
//printf("%s\n",newname);
//char newname[30]={0};
//strcpy(newname,fileinfo.name);
//const char *newname=fileinfo.name;
//const char *oldname="ZCY.txt";
//printf("newname=%s\n",newname);
rename("C:\\Users\\admin\\Desktop\\123\\ZCY.txt","C:\\Users\\admin\\Desktop\\123\\ZCYMIT.txt");
printf("Hello World\n");
printf("转换成功,已输出txt文件\n");
_findclose(handle);
fclose(fp);
fclose(fp2);
system("pause");
return 0;
}
这是完整的代码
#include<string.h>
#include <io.h>
#include<stdlib.h>
#define MAX_LINE 11
#define ALL_TIME 200
const char *to_search="C:\\Users\\admin\\Desktop\\Glu算法\\*.txt"; //欲查找的文件,支持通配符
FILE *fp;
FILE *fp2;
int main()
{
system("color f1");
//printf("请输入想得到最后x秒内的时间电流数据(/s):\n形式如:50\n");
char buf[MAX_LINE]; /*缓冲区*/
int t1;
scanf("%d",&t1);
int n=0;//已经处理的文件数量
//char newname[20]={0} ;
//char prefix[10]="MIT_" ;
long handle; //用于查找的句柄
struct _finddata_t fileinfo; //文件信息的结构体
fp = fopen("C:\\Users\\admin\\Desktop\\Glu浓度算法\\ZCY.txt", "w+");//新建一个txt文件: ZCY-info.txt
if (fp==0)
{
printf("can't open file\n");
return 0;
}
handle=_findfirst(to_search,&fileinfo); //第一次查找
if(-1==handle)
return -1;
//printf("concentration/mMCurrunt(aver%ds-%ds)/uA\n",t1,t2);
//int c=getnd(fileinfo.name);
//printf("%d",c);
if((fp2 = fopen(fileinfo.name,"r"))==NULL)
{
perror("fail to read");
exit (1) ;
}
int m=0;
int k=0;
float temp_t=0;//时间
float current=0;
int g=0;
while(fgets(buf,MAX_LINE,fp2)!= NULL)
{
if(m%2==0)
{
temp_t=atof(buf);
//printf("temp_t=%f\n",temp_t);
if(temp_t>ALL_TIME-t1)
k=1;
}
if(k==1&&buf!=NULL)
{
if(m%2==0)
{
temp_t=temp_t-ALL_TIME+t1+n*t1;
fprintf(fp,"%f, ",temp_t);//写入时间数据
}
if(m%2==1)
{
fprintf(fp,"%s",buf);//写入电流数据
}
}
m++;
}
//printf("%f\n",aver/n);
//fprintf(fp,"%d",c); //打印出信息
//fprintf(fp,"%f\n",aver/n); //打印出信息
//printf("k=%d\n",k);
//printf("Hello World\n");
//sprintf(newname,"%s%s",prefix,fileinfo.name);
//printf("%s\n",newname);
//char newname[30]={0};
//strcpy(newname,fileinfo.name);
//const char *newname=fileinfo.name;
//const char *oldname="ZCY.txt";
//printf("newname=%s\n",newname);
rename("C:\\Users\\admin\\Desktop\\123\\ZCY.txt","C:\\Users\\admin\\Desktop\\123\\ZCYMIT.txt");
printf("Hello World\n");
printf("转换成功,已输出txt文件\n");
_findclose(handle);
fclose(fp);
fclose(fp2);
system("pause");
return 0;
}
这是完整的代码