The main problem is the missing '\0', to define a 5 characters string correctly and initialize it from an array of char with an initializer list this is how it should be
char buffer[6] = {'s', 'd', 'f', 'd', 'f', '\0'};
the second variant in your code si wrong because the array can only store 5 characters, so again
char a[6] = "sdfdf";
/* ^ 6 instead of 5 */
you cannot expect any of the functions following that part of the code to work, when you have a missing '\0'.
All of the printf() with the "%s" spcifier and strlen() expect this last special value '\0' or 0 if you prefer, to be there, when it's not, then these functions invoke undefined behavior because they go beyond the end of the array searching for the '\0'.
strlen(buffer)did not tell you42.12.void main(), find get a better one. Useint main(void). (And you omitted#include <stdio.h>.)