CCS 3.3 操作C函数读写文件
转自: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\t%.15lf\t%.15lf\n", g[0],g[1],g[2] );
}
CLOSEFILE_G: fclose(fp_G);
CLOSEFILE_A: fclose(fp_A);
CLOSEFILE_T: fclose(fp_T);
fclose(fp_Out);
}