#include <stdio.h>
#define FILENAME "mylife.txt"
int main() {
int a, b, n;
FILE *fp;
printf("input integer a and b.\n");
printf("a = ");
scanf("%d", &a);
printf("b = ");
scanf("%d", &b);
if ((fp = fopen(FILENAME, "wt")) != NULL) {
printf("now writing to the file %s the value of a + b.\n", FILENAME);
fprintf(fp, "%d\n", a + b);
printf("finished.\n");
fclose(fp);
}
if ((fp = fopen(FILENAME, "rt")) != NULL) {
printf("now reading from the file %s the integer.\n", FILENAME);
fscanf(fp, "%d", &n);
printf("finished.\n");
printf("In the file '%s', the value '%d' has been written.\n", FILENAME, n);
fclose(fp);
}
return 0;
}
/* end */