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