gpt4 book ai didi

c - 调试断言失败,表达式流 != nullptr

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:52 25 4
gpt4 key购买 nike

使用 Visual Studio IDE,用 C 语言编写。程序正在读取一个基本的 .txt 文件,将华氏度转换为摄氏度,然后写入新的 .txt 文件 为什么找不到 .txt 文件?这是我的代码:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
double tempArray[30];
double temp;
double sum = 0;
int input_status;
int count = 0;
double convert;
FILE *infile, *outfile;
infile = fopen("temperature.txt", "r");
if (infile == NULL) {
perror("Failed: ");
return 1;
}
outfile = fopen("results.txt", "w");

int i = 0;
input_status = fscanf(infile, "%lf", &temp);
double max, min = temp;
while (input_status != EOF)
{

tempArray[i] = (temp - 32) * 5 / 9; ;
sum += tempArray[i];

fprintf(outfile, "%f \n", tempArray[i]);

if (tempArray[i] > max)
max = tempArray[i];

if (tempArray[i] < min)
min = tempArray[i];

count++;
i++;

input_status = fscanf(infile, "%lf", &temp);

}

double average = sum / count;

fprintf(outfile, "\n The average of the temperatures is %f \n", average);
fprintf(outfile, "\n The maximum of the temperatures is %f \n", max);
fprintf(outfile, "\n The minimum of the temperatures is %f \n", min);

fclose(infile);
fclose(outfile);
system("pause");

here's where the .txt file is

this is the error code i received

最佳答案

我将文件命名为“temperature.txt”,它已经是一个.txt文件,所以文件名实际上是“temperature.txt.txt”。小错误,大问题。感谢你们的帮助。

关于c - 调试断言失败,表达式流 != nullptr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38780008/

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