examples/strfilter.c
char *strfilter1(char *string, char *letters) {
    char buffer[strlen(string)+1];
    int j = 0;

    // TODO: hoist strlen out of the loop!
    // See "Accidentally quadratic"
    for (int i=0; i<strlen(string); i++) {
        char *ptr = strchr(letters, string[i]);
        if (ptr) {
            buffer[j++] = string[i];
        }
    }
    buffer[j] = '\0';
    return strdup(buffer);
}
//All string functions have the DESTINATION FIRST
All string functions have the DESTINATION FIRST
All string functions have the DESTINATION FIRST
char *strfilter1(char *string, char *letters) {
    char buffer[strlen(string)+1];
    int j = 0;
    for (int i=0; i<strlen(string); i++) {
        char *ptr = strchr(letters, string[i]);
        if (ptr) {
            buffer[j++] = string[i];
        }
    }
    buffer[j] = '\0';
    return strdup(buffer);
}
char * strfilter1 ( char * string , char * letters ) { char buffer [ strlen ( string ) + 1 ] ; int j = 0 ; for ( int i = 0 ; i < strlen ( string ) ; i ++ ) { char * ptr = strchr ( letters , string [ i ] ) ; if ( ptr ) { buffer [ j ++ ] = string [ i ] ; } } buffer [ j ] = ' \0 ' ; return strdup ( buffer ) ; }
All string functions have the DESTINATION FIRST
All string functions have the DESTINATION FIRST
// TODO: hoist strlen out of the loop! // See "Accidentally quadratic"