/* file-write.c demonstrates the following: - use of argc and argv[] - FILE * type - stderr - fopen(), fclose() - fprintf() prints a sequence of numbers in text format with line breaks between each number */ #include #include int main(int argc, char *argv[]) { FILE *outFile; char c; if (argc != 2) { fprintf(stderr, "\nusage: executable output-file.\n"); exit(1); } if ((outFile = fopen(argv[1], "w")) == NULL) { fprintf(stderr, "Can't open %s for output\n", argv[1]); exit(1); } for (c = 60; c < 70 ; c++) fprintf(outFile, "%d\n", c); /* format as decimal integer, not char */ fclose(outFile); return 0; }