Lab-9

Split Strings

Announcements

There will be 5 minutes’ quiz available on Blackboard at the beginning of each of the lab session. Please sign in to your Blackboard account and finish the quiz individually. Most of your time should be focused on finishing the lab activity question.

You must work with a single partner i.e., in a group of 2 (If there are an odd-number of students in the class, your TA will make an adjustment). You must take turns being the “driver” and the “navigator” while working on the lab activity.

Lab Grading policy 

You must work with a partner for credit. 

There are 3 questions. The maximum score is 2, where each question is worth 1 point. Question 3 is extra credit. To get a grade, you must get graded by the TA in the lab before the lab ends. TAs will not be grading after the 50 minutes of the lab session are over. Once you finish your work, please raise your hand and show your work to the TA during the last 10 minutes of lab or whenever you finish, the earlier of the two.

Lab Activity Overview

You are required to implement "Split Function" from scratch. In many programming languages, to split a sentence into a word list, you just need to use split() function. 

For instance in Python:

sent = "The quick brown fox jumped over the lazy dog"

word_list = sent.split()  ## comment: word_list is ['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog']

Python as a more higher level script language, it is written in C language. Today, we will explore how to explore how to do similar work of split function from scratch. Note that, our way of implement split() function might not be the best way. Maybe it is not efficient in both speed and memory. We just explore one way of implementation.

Tasks:

1. Print each word of the original string on its own line without any space character.

The

quick

brown

fox

jumped

over

the

lazy

dog

You could use whatever method to traverse the string which is a char array to achieve this goal to get 1 point. 

You might need length() function, which returns the length of a string. You could refer to the solution of Lab-8 for length() function.

2. Write a split function that takes the string as one parameter, returns a 2-D array, which stores each word at each row. 

Store words in a 2-D array, remembering to add '\0' character at the last of the string to indicate the end of each word. 

Such as illustrated in the figure below:

3. Using the 2-D array which stores a word in each row to find out the longest word.

Please search TODO in the attached C file to find the functions which need to be finished. Please use the required parameters without changing it.  

Please download the attached C code and start building on it to finish today's lab.

3-7-2017