Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Write a function right_align that takes three parameters - (1) a constant pointer to a source string (i.e., the address of the first character
1. Write a function right_align that takes three parameters - (1) a constant pointer to a source string (i.e., the address of the first character of the string, which is represented with a char array), (2) a pointer to a result string, and (3) the length of the result string, including the NUL byte. The function places in the result char array a copy of the source string, (1) right-aligned, and (2) with all trailing spaces removed. You can assume the result char array will be long enough to contain the created string. The function returns one of two values: FAILURE or SUCCESS (defined in file text_manipulation.h). a. FAILURE - if either the source or result string is NULL or its length is 0 . In this case the result char array must not be modified (it keeps its original value) b. FAILURE - if the length of the result string is too short to represent the source string (after removing the trailing spaces). In this case the result char array must not be modified (it keeps its original value) c. SUCCESS - if a copy of the source string is placed in the result char array, (1) right-aligned, and (2) with all trailing spaces removed. 2. Write a function compact that takes two parameters - (1) a pointer to a string (i.e., the address of the first character of the string, which is represented with a char array) and (2) an out parameter, which is a pointer variable to an integer. The function will compact the string by removing all spaces in the string. After the function call, the string should only include non-whitespace characters from the original string, followed by a NULL byte. If the second parameter is not NULL, the function will set the out parameter to the number of words in the string parameter. The function returns one of two values: FAILURE or SUCCESS (defined in file text_manipulation.h). a. FAILURE - if either the string is NULL or its length is 0 . In this case the string must not be modified (it keeps its original value) b. FAILURE - if the second parameter is NULL c. SUCCESS - the string compaction is done successfully and the out parameter word count is set to the integer variable, of which address is passed into the function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started