CCS 3.3 操作C函数读写文件
2019-07-13 14:42发布
生成海报
转自:http://www.cnblogs.com/because/archive/2012/07/07/2580356.html
#include "stdio.h"
int main()
{
FILE *fp_G,*fp_A,*fp_T,*fp_Out;
double g[3];
double a[3];
double t;
double tmp=0;
fp_G=fopen("E:\2-DSP\C6726\Prj\Test2\g.txt","r");
fp_A=fopen("E:\2-DSP\C6726\Prj\Test2\a.txt","r");
fp_T=fopen("E:\2-DSP\C6726\Prj\Test2\t.txt","r");
fp_Out=fopen("E:\2-DSP\C6726\Prj\Test2\outtofile.txt","w");
while(1)
{
/* 读文件 */
for(int i=0;i<3;i++)
{
if(fscanf(fp_G,"%lf",&tmp)!=EOF)
{
g[i]=tmp;
}
else
{
goto CLOSEFILE_G;
}
}
for(int i=0;i<3;i++)
{
if(fscanf(fp_A,"%lf",&tmp)!=EOF)
{
a[i]=tmp;
}
else
{
goto CLOSEFILE_A;
}
}
if(fscanf(fp_T,"%lf",&tmp)!=EOF)
{
t=tmp;
}
else
{
goto CLOSEFILE_T;
}
/*写文件*/
fprintf( fp_Out, "%.15lf %.15lf %.15lf
", g[0],g[1],g[2] );
}
CLOSEFILE_G: fclose(fp_G);
CLOSEFILE_A: fclose(fp_A);
CLOSEFILE_T: fclose(fp_T);
fclose(fp_Out);
}
作者:wanglei_wan
出处:http://www.cnblogs.com/because/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮