I have written a function like this, when the parameter x is even it doesn't work as desired, for example if I type printf("%s",maxCharac(2)) in main it will print aa and an extra character next to it, but with an odd number it works properly. 
char *maxCharac(int x)
{
    char *str=(char*)malloc(sizeof(char)*x);
    for(int i=0;i<x;i++)
    {            
        str[i]='a';
    }
    return str;   
}
 
     
     
    