Question: 4 Exercise: Trimming excess spaces Exercise 4 : Complete the implementations of the functions below according to the specification given in the comment before each

4 Exercise: Trimming excess spaces

Exercise 4: Complete the implementations of the functions below according to the specification given in the comment before each function. Do not modify main().

#include  #include  #include  /* condense_spaces(str, output) Given a string str, copy the contents into the string output, deleting any runs of consecutive spaces. For example, multiple spaces between words should be condensed into a single space. Multiple spaces at the beginning and end of the string should also be condensed into a single space. Use the isspace() function to detect whether a character is a space. */ void condense_spaces(char str[], char output[]){ /* Your Code Here */ } /* remove_leading_spaces(str, output) Given a string str, copy the contents into the string output, ignoring any leading spaces (spaces at the beginning of the string). */ void remove_leading_spaces(char str[], char output[]){ /* Your Code Here */ } /* remove_trailing_spaces(str, output) Given a string str, copy the contents into the string output, ignoring any trailing spaces (spaces at the end of the string). */ void remove_trailing_spaces(char str[], char output[]){ /* Your Code Here */ } int main(){ char S1[] = "Hello World "; char S2[] = " "; //Contains 0 words, 6 characters char S3[] = "CSC 111 Spring 2018"; char S4[] = " raspberry pear pineapple banana "; char S5[] = " <-- spaces at the beginning, spaces at the end --> "; //Make a new array for the output char W[1000]; printf("S1: \"%s\" ", S1); condense_spaces(S1, W); printf("With spaces condensed: \"%s\" ", W); remove_leading_spaces(S1, W); printf("With leading spaces removed: \"%s\" ", W); remove_trailing_spaces(S1, W); printf("With trailing spaces removed: \"%s\" ", W); printf(" "); printf("S2: \"%s\" ", S2); condense_spaces(S2, W); printf("With spaces condensed: \"%s\" ", W); remove_leading_spaces(S2, W); printf("With leading spaces removed: \"%s\" ", W); remove_trailing_spaces(S2, W); printf("With trailing spaces removed: \"%s\" ", W); printf(" "); printf("S3: \"%s\" ", S3); condense_spaces(S3, W); printf("With spaces condensed: \"%s\" ", W); remove_leading_spaces(S3, W); printf("With leading spaces removed: \"%s\" ", W); remove_trailing_spaces(S3, W); printf("With trailing spaces removed: \"%s\" ", W); printf(" "); printf("S4: \"%s\" ", S4); condense_spaces(S4, W); printf("With spaces condensed: \"%s\" ", W); remove_leading_spaces(S4, W); printf("With leading spaces removed: \"%s\" ", W); remove_trailing_spaces(S4, W); printf("With trailing spaces removed: \"%s\" ", W); printf(" "); printf("S5: \"%s\" ", S5); condense_spaces(S5, W); printf("With spaces condensed: \"%s\" ", W); remove_leading_spaces(S5, W); printf("With leading spaces removed: \"%s\" ", W); remove_trailing_spaces(S5, W); printf("With trailing spaces removed: \"%s\" ", W); printf(" "); return 0; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!