So basically this takes in a string and key. The length of the key determines the amount of columns in the matrix. However, my code doesn't seem to work.
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
int main(){
char key[50];
char line[256];
printf("Enter your string:");
if (fgets(line, sizeof line, stdin) == NULL) {
fprintf(stderr, "No line read\n");
exit(EXIT_FAILURE);
}
printf("Enter your key");
if (fgets(key, sizeof key, stdin) == NULL) {
fprintf(stderr, "No line read\n");
exit(EXIT_FAILURE);
}
int len = strlen(line);
if (len && line[len - 1] == '\n')
line[--len] = '\0';
int len1 = strlen(key);
if (len1 && key[len1 - 1] == '\n')
key[--len]= '\0';
printf("%s\n", line);
printf("%s\n", key);
gridStr(line,key);
}
void gridStr(char *line, char *key)
{
int mat[10][10];
int j=0;
int ctr=j;
printf("The matrix is:\n");
for(i=0;i<strlen(line);i++)
{
for(j=j;ctr<strlen(key);j++)
{
if(line[j]!='\0')
{
mat[i][ctr]=line[j];
printf("%c",mat[i][j]);
ctr++;
}
else
{
}
}
}
}