Assignment 9
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
- Your
.c
file which contains your C program - 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.