What's Here?
- Members: 244,263
- Replies: 693,077
- Topics: 113,148
- Snippets: 3,863
- Tutorials: 935
- Total Online: 1,247
- Members: 72
- Guests: 1,175
|
This function removes extra spaces between a string.
|
Submitted By: born2c0de
|
|
|
Rating:
|
|
Views: 2,128 |
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
|
|
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|