Question: C PROGRAMMING Part 2: echo with a twist Write a program, named twecho, that takes words as command line arguments, and prints each word twice,

C PROGRAMMING

C PROGRAMMING Part 2: echo with a twist Write a program, named

"twecho", that takes words as command line arguments, and prints each word

twice, once as is and once all-capitalized, separated by a space. For

Part 2: echo with a twist Write a program, named "twecho", that takes words as command line arguments, and prints each word twice, once as is and once all-capitalized, separated by a space. For example, ./twecho hello world dude should output: hello HELLO world WORLD dude DUDE Your program should handle any number of arguments. You can receive the command line arguments if you start your main() function in the following way: int main(int argc, char **argv) Please refer to section 5.10 in K&R2. In particular, the picture on page 115 depicts clearly how the command line argument strings are stored in memory. Here are some requirements and hints: - You must use the main() function exactly as given below. You CANNOT modify the main function. Your job is to implement other functions that main() calls. int main(int argc, char **argv) { if (arge #include #include #include You can put duplicateArgs() and freeDuplicatedArgs() in the same.c file as main(). - In duplicateArgs() function, you are making a "copy" of the memory structure shown in the picture on page 115, K&R2. You will call malloc() once for the overall array where each element is of type char*, then you will call malloc() for each element of that array, each of which will hold the all-cap version of each argument. Of course, you will have to copy each string character-by-character, capitalizing as you go. Some useful library functions for doing this include strlen() and toupper(). See the textbook. Don't forget that the last element of the overall array of char*'s is a NULL pointer (see the picture in page 115, K&R2). - In freeDuplicatedArgs() function, you must free() everything you malloc() ed. First free () all individual strings, and then free () the overall array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!