Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago