String Stuff

The questions below are due on Monday October 12, 2026; 11:59:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Back to Exercises

C has a lot of built in string manipulation functions, but what’s the fun in using these functions if we can make them instead?

We are going to use these strings to write a story. But we don’t want to do too much work! While writing our rough draft, we realize that we have a lot of sentences that are repeated many times. With your incredible knowledge of C, you decide to automate the process of repeating these strings by using strcpy.

strcpy is a very common function in C. It copies one string to another string. This function takes in two pointers, one pointer to the string that we would like to copy (src), and one pointer to the string that we would like to copy to (dest). Implement the strcpy functionality below in the function we've named myStrcpy. Assume that the array pointed to by dest is large enough to contain the string from src. Do not forget to add the string terminating character to the end of the dest array.

Great job! However, after finishing our rough draft, we realize that our character count is far too low to get a good grade on our paper! But we have a solution: for every word in our story, we will simply double every letter in every word! Copy and paste your myStrcpy code from above into this code box and modify your function such that every character in the function is repeated twice! Note, the terminating character doesn’t need to be repeated, and assume the lengths of the arrays once again work out.

Awesome! After writing your individual lines of your story, you now want to be able to join all the lines together into one big continuous story! We often are able to concatenate two strings together using strcat in C. We will first write an implementation of this function which we've named myStrcat! This function should concatenate the src string to the end of the dest string.

Finally, use your myStrcat to concatenate a list of strings together! Write a function that takes in a list of num_texts strings, texts, and concatenate them all into story. You may assume the array pointed to by story is large enough to contain the concatenated string. You may use the previously defined myStrcat and myStrcpy functions.

Note again that the string.h functional equivalents to the myStrcpy and myStrcat functions you've implemented today are strcpy and strcat, respectively. We simply used different names for today's implementations to prevent compilation errors that occur when trying to declare functions with the same name as those that already exist in C's standard libraries.

Back to Exercises