Skip to content

Strip a Character from the Start of a String

Advance a pointer past every leading occurrence of a character and return the first position that is not that character.

Language: C

Added on: 21st August 2026

char *stripfront(char *str, char c)
{
    if (str == NULL) {
        return NULL;
    }
    while (*str != '\0' && *str == c) {
        str++;
    }
    return str;
}

Caveats

Does not allocate or copy. NULL input returns NULL.