Pagini recente » Monitorul de evaluare | Cod sursa (job #745196) | Cod sursa (job #2148733) | Cod sursa (job #2097703) | Cod sursa (job #3181266)
#include <stdio.h>
int main() {
FILE *inputFile, *outputFile;
int number1, number2, sum;
inputFile = fopen("example.txt", "r");
if (inputFile == NULL) {
printf("Error opening the input file.\n");
return 1;
}
if (fscanf(inputFile, "%d", &number1) != 1) {
printf("Error reading the first number.\n");
fclose(inputFile);
return 1;
}
if (fscanf(inputFile, "%d", &number2) != 1) {
printf("Error reading the second number.\n");
fclose(inputFile);
return 1;
}
fclose(inputFile);
sum = number1 + number2;
outputFile = fopen("adunare.out", "w");
if (outputFile == NULL) {
printf("Error opening the output file.\n");
return 1;
}
fprintf(outputFile, "%d", sum);
fclose(outputFile);
printf("Sum successfully written to adunare.out.\n");
return 0;
}