C语言中如何吧结果输入到txt文件中

#include <stdio.h>
#include<math.h>

int main()
{
int N,n,d,S,s,Sb,ai,S0,E0,angle,f,v; //N:组元,d:排列间距,n:子波波长,S相位角,s,激发相位差,Sb空间相位差,ai激励振幅,S0总场强,E0能量,angle:方位角,f:子波主频,v:速度//
double X,X0,pi,SS;
FILE *file=NULL;
fopen(&file, "C:\\1.txt", "a");
pi=3.14;
printf("pless input N and press enter");
N=getchar();
printf("pless input d and press enter");
d=getchar();
printf("pless input n and press enter");
n=getchar();
printf("pless input S and press enter");
S=getchar();
printf("pless input s and press enter");
s=getchar();
if(angle=0,angle<=360,angle++)
{
S=2*pi*f*d*cos(angle)/v+Sb;//计算相位角//
E0=abs(sin(N/2*S)/N*sin(1/2*s));//计算能量响应//
printf("angle=%d\n",angle);
printf("E0=%d\n",E0);
fprintf(file, "angle=%d\n",angle);
fprintf(file, "E0=%d\n",E0);
}
return 0;
}
上面是我的代码,我想把E0和S输出到txt文件内,但是在fopen(&file, "C:\\1.txt", "a");这这行代码处报错:function does not take 3 parameters,不会改了,求帮我改一下,谢谢各位了

公式有没有错我就不知道了

#include <stdio.h>
#include<math.h>

int main()
{
int N,n,d,S,s,Sb,ai,S0,E0,angle,f,v; //N:组元,d:排列间距,n:子波波长,S相位角,s,激发相位差,Sb空间相位差,ai激励振幅,S0总场强,E0能量,angle:方位角,f:子波主频,v:速度//
double X,X0,pi,SS;
FILE *file;
file=fopen("1.txt", "w");
pi=3.14;
printf("pless input N and press enter");
N=getchar();
printf("pless input d and press enter");
d=getchar();
printf("pless input n and press enter");
n=getchar();
printf("pless input S and press enter");
S=getchar();
printf("pless input s and press enter");
s=getchar();
for(angle=0;angle<=360;angle++)
{
S=2*pi*f*d*cos(angle)/v+Sb;//计算相位角//
E0=abs(sin(N/2*S)/N*sin(1/2*s));//计算能量响应//
printf("angle=%d\n",angle);
printf("E0=%d\n",E0);
fprintf(file, "angle=%d\n",angle);
fprintf(file, "E0=%d\n",E0);
}
fclose(file);//关闭文件
return 0;
}

追问

十分感谢,最后请问一个小问题,最后输出的txt是在哪个路径?

追答

和代码在同一个文件夹,还有,getcher()是获取字符

温馨提示:答案为网友推荐,仅供参考
相似回答