/* fileio.c Jeff Ondich, 26 April 2019 Part of a quick intro to C */ #include #include int main(int argc, char *argv[]) { // Check the command-line syntax and offer a usage statement // if it's not OK. It's conventional to return 1 to indicate // to the shell/terminal that an error occurred while running // this program. if (argc != 3) { fprintf(stderr, "Usage: %s inputFileName outputFileName\n", argv[0]); return 1; } // OK, we have file names. Let's try opening them for reading (inputFile) // and writing (outputFile). FILE *inputFile = fopen(argv[1], "r"); if (inputFile == NULL) { fprintf(stderr, "We could not open the file %s for reading.\n", argv[1]); return 1; } FILE *outputFile = fopen(argv[2], "w"); if (outputFile == NULL) { fprintf(stderr, "We could not open the file %s for writing.\n", argv[2]); return 1; } // Yipee, our files are ready to go! Read one character at a time out of // the input file and write it in upper case to the output file. char ch; while ((ch = fgetc(inputFile)) != EOF) { fputc(toupper(ch), outputFile); } // Be nice and clean up after yourself. fclose(inputFile); fclose(outputFile); return 0; }