Pushok icon

Two functions which remove selected characters

Pushok | PRO | 04/17/11 11:17:33 AM UTC | 0 ⭐ | 515 👁️ | Never ⏰ | []
C |

660 B

|

None

|

0 👍

/

0 👎

void delchar(char* str, char ch)
{
        if(str == 0 || *str == 0) return;
 
        char* ptr = str;
        while(*ptr != 0) if(*ptr == ch) break; else ptr++;
 
        while(1)
        {
                char c = *ptr;
                *ptr = ptr[1];
                ptr[1] = c;
                if(*ptr == 0) return; else ptr++;
        }
}
 
void delallchar(char* str, char ch)
{
    if(str == 0 || *str == 0) return;
    char* ptr = str;
    while(*ptr != 0) 
    {
        if(*ptr == ch)
        {
            char* cstr = ptr;
            while(1)
            {
                char c = *cstr;
                *cstr = cstr[1];
                cstr[1] = c;
                if(*cstr++ == 0) break;
            }
 
            continue;
        }
 
        ptr++;
    }
}

Comments