This could work too:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char (*array)[4][4] = NULL;
int n_arrays = 0;
int row = 0, col = 0;
int ch;
int i;
unsigned long total = 0;
while((ch = getchar()) != '\n' && ch != EOF)
{
if(!row && !col)
{
array = realloc(array, sizeof(*array) * (n_arrays + 1));
n_arrays++;
}
array[n_arrays - 1][row][col] = ch;
total++;
if(++col == 4)
{
col = 0;
if(++row == 4)
row = 0;
}
}
row = col = i = 0;
while(total--)
{
printf("%c ", array[i][row][col++]);
if(col == 4)
{
col = 0;
putchar('\n');
if(++row == 4)
{
row = 0;
i++;
putchar('\n');
}
}
}
free(array);
putchar('\n');
return 0;
}
My output:
Code:
itsme@dreams:~/C$ ./4x4
This sentence is more than 32 characters long.
T h i s
s e n
t e n c
e i s
m o r
e t h
a n 3
2 c h
a r a c
t e r s
l o n
g .
itsme@dreams:~/C$