Starting from:

$30

CMSC216 Exercise 2 -Solved

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 func
tion 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 fifile 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 specifified 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 fifield 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 fifile 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. 


your program generates the expected results on the submit server. 
4. Your code must be written in the fifile text manipulation.c. 
5. Do not add a main function to the text manipulation.c fifile. 
6. To compile a public test, compile your text manipulation.c fifile along with a public test fifile. For example: 
gcc public01.c text manipulation.c 
7. One source bugs is forgetting to add a null character to a string. 
8. All your C programs in this course should be written using the compiler gcc with the options defifined at 
http://www.cs.umd.edu/~nelson/classes/resources/setting_gcc_alias/ 
9. Your program should be written using good programming style as defifined at 
http://www.cs.umd.edu/~nelson/classes/resources/cstyleguide/ 
10. You just need to implement the two functions described above. You may write additional functions if 
you want, but defifine them as static. 
11. Do not change the text manipulation.h fifile provided. 
12. You are encourage to defifine your own tests (similar to public01.c, public02.c, etc.). 
13. You can use the C string library (string.h). 
14. Do not use any functions from ctype.h. 
15. You can assume the result char array will be long enough to contain the string functions will create. 
16. Do not use dynamic memory allocation. 
17. The example ptr add sub overview.c reviews concepts associated with this exercise. 


More products