Starting from:

$20

CMSC216-Exercise2 Solved

For this exercise you will implement two functions that manipulate text. The prototypes for the functions can
be found in file text manipulation.h.
1. int remove spaces(const char *source, char *result, int *num spaces removed);
This function places a copy of the source string in the out parameter result where all leading and trailing
spaces have been removed. If the out parameter num spaces removed is different than NULL, the function will set the integer associated with the parameter to the number of spaces removed. The function
will return one of two values: FAILURE or SUCCESS (see file text manipulation.h).
a. FAILURE - if the source string is NULL or its length is 0. In this case the result string is not assigned
a new value (it keeps its original value).
b. SUCCESS - if spaces can be removed or no spaces are present.
2. int center(const char *source, int width, char *result);
This function generates a new string into the result out parameter where the source input string has
been centered in a string with length specified by the width parameter. Center the string by adding (to
the left and right of the original string) a number of spaces that corresponds to (width - source string
length) / 2. Notice that the resulting centered string has a length that is less than width when (width -
source string length) is odd. For example, if we were to center “dogs” in a field with of 7, the resulting
string is “ dogs ” (1 space to the left, 1 space to the right). The function returns one of two values:
SUCCESS or FAILURE (see file text manipulation.h).
a. FAILURE - if source is NULL, if source length is 0, or if the width is less than the source length.
b. SUCCESS - if item is centered.
You should look at the public tests in order to understand the functionality associated with the functions you
must implement. For this exercise, you can assume the user will not provide a string containing only blank
characters. In addition, if a string has multiple words, the spaces between those words must be preserved.

More products