char* appends( char* str, char* text ) { // not allocated! if ( !str ) { str = malloc( strlen( text ) + 1 ); strcpy( str, text ); return str; } int size = ( ( strlen( str ) + strlen( text ) ) ) + 2; str = realloc( str, size ); strcat( str, text ); return str; } char* HTMLEntities( char* input ) { int i; int length = strlen( input ); char* copy = NULL; for( i = 0; i < length; i++ ){ switch( input[i] ) { case '<': copy = appends( copy, "<" ); break; case '>': copy = appends( copy, ">" ); break; case '&': copy = appends( copy, "&" ); break; case '"': copy = appends( copy, """ ); break; case '\'': copy = appends( copy, "'" ); break; default: copy = appendc( copy, input[i] ); break; } } return copy; }