我编了个小程序,想把他的计算结果自己命名一个文件输出,怎么实现?
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <fstream.h>
#include <stdio.h>
void main(void)
{
FILE *out;
double innum[1024];
int ai;
int i;
int ci=0;
int hci=0;
for(ai=0;ai<1024;ai++)
{
innum[ai]=0;
}
char outfile[10],filename[200],cIn;
cout<<"*************************************************"<<"\n";
cout<<"请给出调用文件名字 (*.txt):";
cin>>filename;
ifstream f1;
f1.open(filename,ios::in);
if(f1)
{
while(f1>>innum[ci])
ci++;
}
else
{
cout<<"File open error!"<<"\n";
exit(1);
}
hci=ci;
f1.close();
printf("请给出输出文件名字:");
scanf("%s",&outfile);
out=fopen("outfile.txt","w");
printf("%s",outfile);
double *t,*k;
t=new double[hci];
k=new double[hci];
for(i=0;i<hci;i++)
{
t[i]=innum[i];
printf("%1.4f\n",t[i]);
}
fprintf(out,"变异系数=0.0286\nkz值如下:\n");
for(i=0;i<hci/4;i++)
{ k[i]=0.05/(t[4*i+1]*sqrt(1/t[4*i]+t[4*i+2]*t[4*i+2]*(t[4*i+3]*t[4*i+3]-1)-.0.5*t[4*i+2]*t[4*i+3]));
printf("%1.4f\n",k[i]);
fprintf(out,"%d: %1.4f\n",30-i,k[i]);
}
fclose(out);
}