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...
IN MIPS ASSEMBLY Macro File: Create macros to print an int, print a char, print a...
IN MIPS ASSEMBLY Macro File: Create macros to print an int, print a char, print a string, get a string from the user, open file, close file, read file, and allocate heap memory. You can use more macros than these if you like. Main Program File: Allocate 1024 bytes of dynamic memory and save the pointer to the area. The main program is a loop in which you ask the user for a filename. If they enter nothing for the...
** 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...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
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...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly dividing by b. Each time a division is performed the remainder and quotient are saved. At each step, the dividend is the quotient from the preceding step; the divisor is always b. The algorithm stops when the quotient is 0. The number in the new base is the sequence of remainders in reverse order (the last one computed goes first; the first one goes...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are two ways to write loops: (1) iterative, like the for-loops we're used to using, and (2) recursive. Your prerequisite preparation for this course should have exposed you to both, although your working knowledge of recursive loops may not be as strong as that of iterative loops. Consider the following iterative function that prints an array of characters backward: #include <iostream> #include <cstring> // print...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT