What's Here?
- Members: 98,767
- Replies: 387,069
- Topics: 58,108
- Snippets: 2,026
- Tutorials: 546
- Total Online: 1,025
- Members: 36
- Guests: 989
Who's Online?
|
This function removes extra spaces between a string.
|
Submitted By: born2c0de
|
|
Rating:

|
|
Views: 955 |
Language: C
|
|
Last Modified: October 10, 2007 |
|
Instructions: This Code removes only those extra whitespaces which are present between the string and not those which are present in the beginning or at the end of the string. |
Snippet
#include <string.h>
/* The Modifications are Made to the Same String */
void inside_trim(char* x)
{
unsigned int i,pos,nxtchar;
for(i=0;i<strlen(x);i++)
{
if( x[i] == ' ' )
{
pos=i+1;
nxtchar=pos-1;
while(x[nxtchar++] == ' '){}
strcpy(&x[pos],&x[nxtchar-1]);
}
}
}
/* USAGE:
char xyz[]="Does this work?";
printf("\n%s",xyz);
inside_trim(&xyz[0]);
printf("\n%s",xyz);
*/
Copy & Paste
|
|
|
Programming
Web Development
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|