Create a program that copies the data from one file to another while converting all lowercase vowels to uppercase vowels. Your program should accept two arguments: an input file to read from and an output file to copy to. • Your program should check to make sure the output file does not already exist. If it does, print "DESTINATION FILE EXISTS." to stdout. • Print the number of characters changed to stdout using the format string "%d characters changed." • Save your code as prob1.c.
Example Run
$ ./a.out input.txt output.txt
128 characters changed.
Complete code in C:-
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
// Checking if 'c' is a vowel or not.
int isVowel(char c) {
c = toupper(c);
if(c == 'A' || c == 'E' || c == 'I' || c == 'O' || c
== 'U') {
return 1;
}
return 0;
}
int main(int argc, char const *argv[]) {
// Checking if all required command line arguments are
present.
if(argc < 3) {
printf("Missing at least on of the
file name...\n");
exit(0);
}
// Checking if output file already exists or
not?
if(access(argv[2], F_OK) != -1) {
printf("DESTINATION FILE ALREADY
EXISTS...\n");
exit(0);
}
// Opening input file in read mode.
FILE *infp = fopen(argv[1], "r");
// Opening output file in wirte mode.
FILE *opfp = fopen(argv[2], "w");
// Initialize 'changed' variable as 0
// It will count total number of characters which will
be changed.
int changed = 0;
// Readin input file until END OF FILE.
while(!feof(infp)) {
// Reading one character at a
time.
char c = fgetc(infp);
// Checking if it is an
alphabate.
if((c >= 'a' && c <=
'z') || (c >= 'A' && c <= 'Z')) {
// Checking if
it is a vowel.
if(isVowel(c))
{
// Checking if character is already an upper
case character.
char upperC = toupper(c);
if(upperC != c) {
changed += 1;
c = upperC;
}
}
}
// Writting character in output
file.
fputc(c, opfp);
}
printf("WRITTEN SUCCESSFULLY!\n%d Characters
changed\n", changed);
return 0;
}
Content of "input.txt":-
Hi! My name is Abhishek gangwar.
I'm a software engineer.
Content of "output.txt":-
HI! My nAmE Is AbhIshEk gAngwAr.
I'm A sOftwArE EngInEEr.
Screenshot of output:-
Get Answers For Free
Most questions answered within 1 hours.