First of all, you must understand your problem. You have the following diagnostics:
first lines of output are too long 1 character
! . , . abc, ? ? , "1 " .
" ":
buffer[len] = '\0';
...
printf("%c", buffer[len]);
, , \0. ( "unprintable" ), ,
printf("Character '%c', whose code is %d\n", buffer[len], buffer[len]);
, :
. , . .