Question

Create a program that copies the data from one file to another while converting all lowercase...

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.

Homework Answers

Answer #1

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:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a program that filters the data in a CSV file of product data based on...
Create a program that filters the data in a CSV file of product data based on some search word and prints the resulting output to a new file. Additionally, the program will print the number of items filtered to stdout. • Your program should take three arguments: an input file to process, an output file to save the results, and a search word. • If the output file already exists or cannot be opened, warn the user by printing "CANNOT...
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling...
c# please Create a “Main” program which reads a text file called “collectionOfWords.txt”. Include exception handling to check if the file exists before attempting to open it. Read and print each string to the console. Next modify each word such at the first letter in each word is uppercase and all other letters are lowercase. Display the modified word on the console. Creating a text file: Open up Notepad and type in the following words. Save the file as collectionOfWords.txt...
** Language Used : Python ** PART 2 : Create a list of unique words This...
** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT