Visual Studio IDEを使用して、C言語で記述すると、基本的な.txtファイルが読み込まれ、華氏から摂氏に変換され、新しい.txtファイルに書き込まれます。 txtファイル?ここに私のコードは次のとおりです。デバッグアサーションに失敗しました。式ストリーム!= nullptr
#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");
}
this is the error code i received
'fopen'が成功するかどうかはチェックしていません。結果の 'fopen'が失敗したように見えます。 – kaylum
そして、テキストメッセージを画像として投稿しないでください。他の人がコメント/回答の参照のためにそれをより簡単にコピーできるように、テキストとして質問に貼り付けます。 – kaylum
正常に開くかどうかを確認しても、それが成功しない理由は変わりません。 .txtファイルが見つからないのはなぜですか? – Destreation