gpt4 book ai didi

c - double* 和 double 到二元运算符&类型的无效操作数

转载 作者:行者123 更新时间:2023-11-30 18:29:48 25 4
gpt4 key购买 nike

刚开始为类(class)编程和编写 C 代码。我的程序应该从 .txt 文件获取数据,计算,然后将结果打印到 .txt 文件。

我得到:

invalid operands of types double* and double to binary operator&

fscanf(therm, "%lf %lf",&temp &con); 行(靠近底部的 for 循环)

/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "c:\\engr 200\\thermal.txt"
#define outputfile "c:\\engr 200\\results.txt"

/*Main function*/
int main (void)
{

/*Declare and intialize variables*/
double temp, sumtemp = 0.0, con, sumcon = 0.0, tem_con, sumtem_con =
0.0, tsq, sumtsq = 0.0;
int i, ndata;
FILE *therm, *res;

/*Open files*/
therm = fopen (inputfile, "r");
res = fopen (outputfile, "w");

/*Print output headings*/
printf ("******************************************");
printf ("\nTEMPERATURE vs THERMAL CONDUCTIVITY");
printf ("\nby ");
printf ("\n\nTemp Conduct Temp Sqrd Temp*Conduct");

/* Verify input file and read control number */
// NOTE: unmatched 'else' followed, presuming a
// test for 'therm'
if (!therm)
{
printf ("\n\n\n\n ERROR OPENING INPUT FILE.");
printf ("\n\n PROGRAM TERMINATED.\n\n\n");
return 0;
}
else
{
/* Read control number */
fscanf (therm, "%i", &ndata);

/* Compute temp and conductivity data and print results */
for (i = 1; i <= ndata; i++) {
fscanf (therm, "%lf %lf", &temp & con);
sumtemp = sumtemp + temp;
sumcon = sumcon + con;
sumtsq = sumtsq + pow (temp, 2);
sumtem_con = sumtem_con + temp * con;
printf ("\n%3.0f %5.1f %6.1f %6.1f", sumtemp, sumcon, sumtsq,
sumtem_con);
fprintf (res, "%3.0f %5.1f %6.1f %6.1f", sumtemp, sumcon,
sumtsq, sumtem_con);
}
}

/*Close the input file*/
fclose (therm);
fclose (res);

/*Exit the program*/
return 0;
}

你能帮我诊断这个错误吗?

最佳答案

您错过了两个变量之间的逗号,并且还缺少 if 语句。

fscanf(therm, "%lf %lf", &temp &con);

这应该是

fscanf(therm, "%lf %lf", &temp, &con);

应该有一个 if 语句。

/* Verify input file and read control number */

关于c - double* 和 double 到二元运算符&类型的无效操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35445961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com