You are here:

C/remove white space from a string

Advertisement


Question
I have managed to make a program that counts all the characters in a string but how can i remove the white space from a string?
Ex:"  T h i s             i s \t a         \n       \t t e s t \n   \n \n\0"

should be :"This is a test \0"  

Answer
Copy all the characters of this string to another string variable. While doing so, don't add the space charactes (space, or tab).
That is, Scan the string character by character.
Check whether the current character is a space.
If yes, then continue.
If no, then copy this to the new variable.
At the end of scanning, you have the string without character in the new string variable.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.