Verwenden der Visual Studio-IDE, Schreiben in C. Programm liest eine einfache .txt-Datei, konvertiert von Fahrenheit in Celsius und schreibt in eine neue .txt-Datei Warum wird es nicht gefunden? TXT-Datei? Hier ist mein Code:Debug-Assertion fehlgeschlagen, Expression-Stream! = 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
Sie überprüfen nicht, ob 'fopen' erfolgreich ist oder nicht. Sieht so aus, als wäre das 'fopen' für das Ergebnis fehlgeschlagen. – kaylum
Und bitte keine SMS als Bilder. Fügen Sie ihn als Text in die Frage ein, damit andere ihn einfacher für die Referenzierung in Kommentaren/Antworten kopieren können. – kaylum
Auch wenn ich überprüfe, ob es erfolgreich geöffnet wird, ändert sich das nicht, warum es nicht erfolgreich ist. Warum findet es die .txt-Datei nicht? – Destreation