Assignment 9

1 minute read

Due: by the end of the calendar day on Thursday, December 5, 2024

Assignment Requirements

Write a C program which includes a function called join that takes an array of strings as an argument (along with the array’s size, n). The function should return a new string (allocated on the heap with malloc) which is the concatenation of all the strings from the array. The function should have the following prototype:

// Takes an array of n strings and returns
// a new string allocated on the heap
char *join(char **arr, int n)

Testing your function

You should write a main function which calls your function with several test cases. Here’s something you could start with:

int main()
{
    char *my_strings[4] = {"The", "quick", "brown", "fox"};
    char *joined = join(my_strings,4);
    printf("Here is the joined string: %s\n",joined);

    return 0;
}

For this example, the expected output would be

Here is the joined string: The quick brown fox

Grading

This is a 4-point assignment. See the rubric from the syllabus.

What to turn in

Turn in the following items

  1. Your .c file which contains your C program
  2. A .txt file (you can use Notepad, TextEdit, or even Visual Studio Code) where you paste in a sample run of your program that shows how it worked when you ran it

Where to turn it in

Submit your files to the Assignment 9 hand-in form on Blackboard.