program to remove spaces from any string
Hey, this a small code snippet for removing spaces from any string,
void remove_space(char *main) //accepts a string as argument
{
char ch[100];
strcpy(ch,main); // copies string main to ch
int i,j=0;
for(i=0;main[i]!='\0';i++)
{ if(ch[i]==' ') // if any space is encountered then,
{
for(j=i;ch[j]!='\0';j++)
ch[j]=ch[j+1]; // decrements the string.
if(main[i+1]==' ')
i--;
}
}
printf(ch);
}
this small function removes all the spaces from any string. This function can come very handy in several situations.
Try to implement it...
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home