Stack smashing detected or aborted

Why is the stack smashing error occurring in following??I have no idea. Someone pls help!!
`#include<bits/stdc++.h>

using namespace std;

int main()
{ int x,y,len=0;
string str,str1;
getline(cin,str);
int n=str.length();
for(int i=0;i<n;i++)
{
if(str[i]!=’ ')
len++;
}
int l,h;
l=floor(sqrt(len));
h=ceil(sqrt(len));
if((ll)>=len)
{
x=l;
y=l;
}
else if((l
h)>=len)
{

    x=l;
    y=h;
}
else if((h*h)>=len)
{
    x=h;
    y=h;
}

char a[x][y];
for(int i=0;i<x;i++)
{
    for(int j=0;j<y;j++)
    a[i][j]=' ';
}
int p1=0;
//copying str without spaces in str1
for(int i=0;i<n;i++)
{   
    if(str[i]!=' ')
    {
        str1[p1]=str[i];
        p1++;
    }
}
//storing in 2D array
int it=0;
bool flag;
flag=false;
for(int i=0;i<x;i++)
{
    for(int j=0;j<y;j++)
    {   
        if(str1[it]=='\0' || str1[it]==' ')
        {
            flag=true;
            break;
        }
        else
        {
          a[i][j]=str1[it];
          it++;
        }
        
    }
    if(flag==true)
    break;
}
//printing column-wise
for(int i=0;i<y;i++)
{
    for(int j=0;j<x;j++)
    {
        if(a[j][i]!=' ')
        cout<<a[j][i];
    }
    if(i!=(y-1))
    cout<<' ';
}
return 0;

}