/* * Very simple, very contrived example of I/O using files: * Read two integers from input, write to output, filenames "hardcoded" * as in.txt, out.txt. */ #include int main(int argc, char *argv[]) { FILE * infile = fopen("in.txt", "r"); if (infile == NULL) { printf("cannot open input\n"); return 1; } FILE * outfile = fopen("out.txt", "w"); if (outfile == NULL) { printf("cannot open output\n"); return 1; } int a, b; if (fscanf(infile, "%d %d", &a, &b) != 2) { printf("error\n"); return 0; } fprintf(outfile, "%d %d\n", a, b); fclose(infile); fclose(outfile); return 0; }