I am trying to implement a columnar transposition cipher in C and was doing the encryption part but I am facing an issue with the 2d part you can see in the output image.
#include<stdio.h>
#include<string.h>
int main()
{
int arr[10];
int key;
printf("Enter size of key: ");
scanf("%d",&key);
for (int i = 0; i < key; i++)
{
printf("Enter the value of key at pos %d: ",i+1);
scanf("%d",&arr[i]);
}
printf("key is: ");
for (int i = 0; i < key; i++)
{
printf("%d",arr[i]);
}
printf("\n");
char msg[20];
printf("Enter your msg: ");
fflush(stdin);
scanf("%s",&msg);
printf("message is : %s\n",msg);
int msg_len = strlen(msg),row;
printf("Enter number of rows: ");
scanf("%d",&row);
printf("msg size: %d\n",msg_len);
char rect[row][msg_len];
for (int j = 0; j < row; j++)
{
for (int k = 0; k < msg_len; k++)
{
rect[j][k]=msg[k];
//rect[row][msg_len]='\0';
}
}
rect[row][msg_len]='\0';
printf("%s",rect);
return 0;
Expected output is : stackoverflow