In this section, you will study how to remove spaces from the string. You can see in the given example, we have define the string and passed it into two character pointers. The expression p1 = ch, resets the pointer to start. If any punctuation character or whitespace character is found in the *p1 till p1, to be not equal to 0, then ++p1 moves over a whole character otherwise copy the character using the expression *p2++ = *p1++;. The *p2 =
0; appends the string terminator.
ispunct()- finds the punctuation character.
isspace()-finds the whitespace character.
Here is the code:
Output will be displayed as:
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: February 5, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles