If "my system has memory, but it is scattered in different places (fragmented)" means that the heap virtual memory is fragmented and "declare a character array of size 10" means that you create an array of characters of size 10 in the memory stack :
char str[10];
then the array will be created successfully.
" 10" , malloc() ( ):
char *str2;
str2 = (char*) malloc(10 * sizeof(char));
malloc() NULL.