Q:

Delete whitespace from string

I trying make program that delete whitespace from the string.
Someone can give me hand?
int main()
{
    char str[15];
    int i=0;
    gets(str);
    while(str[i] !=0){
        if(str[i] == 32)
        {
            str[i++] = str[i];
            str[i] = str[i++];
        }
    }
    str[strlen(i)] = '\0';
    printf("%s", str);
    return 0;
}

thx

A:

Well since you are using C trim is not an option.
First of all, what are your thoughts on the line:
str[i] = str[i++];
?
This is basically the same as
i++;
Now to the code:
 char *mystring, *read, *write;
 // mystring gehts filled with a null terminated string here
 read = mystring;
 write = mystring;
 while(*read != '\0') {
      if(*read == ' ') 
           read++;
      else 
           *write++ = *read++;
 }
 *write = '\0';

If you like to write to another String, just make write point to the location where you want it to be. Do not forget to check that you have enough room there ;)

