I want to convert a 1d character array to 2d array in a particular format given below
Input-toioynnkpheleaigshareconhtomesnlewx
I want to convert it into this format-
t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x
My approach is -
cin>>n; //n is number of columns and no of rows is unknown
cin.ignore();
while(n!=0)
{
for(i=0;i<40;i++)
{
for(j=0;j<n;j++)
{
cin.get(a[i][j]);
if(a[i][j]=='\n') //this condition because on entering the newline code should stop entering the string
goto jump;
}
for(m=j;m>=0;m--)
{
i++;
cin.get(a[i][m]);
if(a[i][m]=='\n')
goto jump;
}
}
jump:
for(k=0;k<i;k++)
{
for(l=0;l<n;l++)
{
cout<<a[k][l];
}
}