"Doesn't work" isn't much of a description. How exactly doesn't it work would be useful.

Anyway, here's one error: strcpy(str,ch);
strcpy takes two strings, not a string and a char.

Your logic is incorrect for testing the length of the printable string. You should collect characters until you hit a non-printable character (or EOF or the maximum size of str), THEN test the length, and display it if needed. Currently the code checks the length within the collection loop, which means the loop will terminate as soon as the length exceeds 4.