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

    for (int i=0; i<length; i++) {
        char *ptr = strchr(letters, string[i]);
        if (ptr) {
            buffer[j++] = string[i];
        }
    }
    buffer[j+1] = '\0';
    char * res = (char *)malloc(j+1);
    strcpy(res, buffer);
    return res;
}
// TODO: Find everything wrong with the following two functions
Find everything wrong with the following two functions
Find everything wrong with the following two functions
char *strfilter3(char *string, char *letters) {
    int length = strlen(string);
    char buffer[length];
    int j = 0;
    for (int i=0; i<length; i++) {
        char *ptr = strchr(letters, string[i]);
        if (ptr) {
            buffer[j++] = string[i];
        }
    }
    buffer[j+1] = '\0';
    char * res = (char *)malloc(j+1);
    strcpy(res, buffer);
    return res;
}
char * strfilter3 ( char * string , char * letters ) { int length = strlen ( string ) ; char buffer [ length ] ; int j = 0 ; for ( int i = 0 ; i < length ; i ++ ) { char * ptr = strchr ( letters , string [ i ] ) ; if ( ptr ) { buffer [ j ++ ] = string [ i ] ; } } buffer [ j + 1 ] = ' \0 ' ; char * res = ( char * ) malloc ( j + 1 ) ; strcpy ( res , buffer ) ; return res ; }
TODO: Find everything wrong with the following two functions
TODO : Find everything wrong with the following two functions