/* * Program to copy text from input to output, changing case of letters. * * Input: text file "in.txt". * * Output: text file "out.txt", contents the same as "in.txt" except that * uppercase letters have been changed to lowercase, and vice versa. */ #include #include #include int main(void) { FILE * in; FILE * out; int input_char; /* open input file and check result */ in = fopen("in.txt", "r"); if (in == NULL) { printf("unable to open input file\n"); exit(1); } /* open output file and check result */ out = fopen("out.txt", "w"); if (out == NULL) { printf("unable to open output file\n"); exit(1); } /* read characters and copy to output, changing case */ while ((input_char = fgetc(in)) != EOF) { if(isupper(input_char)) { fputc(tolower(input_char), out); } else if (islower(input_char)) { fputc(toupper(input_char), out); } else { fputc(input_char, out); } } /* close files */ fclose(in); fclose(out); printf("Goodbye!\n"); return 0; }