What about constrcting an array with undefined size??
For each line do a gets(), and read all numbers in it. End a line with enter.
If the user writes an empty string the cicle ends, then do the shift stuff.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main(){
int shift;
int array[100][100], bckp[100];
int xlen=100, ylen=0, xline=0, yline=0, i, j, k;
char line[500];
//the newline is also read, therefore buffer flushing isn't necessary
scanf("%d\n", &shift);
if(shift<1) return 0;
while(1){
fgets(line, sizeof(line), stdin);
if(!line[0] || line[0]=='\n') break;
n=strchr(line, '\n');
if(n) *n=0;
for(i=0;line[i];){
while(line[i]==' ') i++;//skip spaces
if(line[i]=='\n')//end of line
break;
array[ylen][xline++]=atoi(line+i);
while(isdigit(line[i])) i++;
}
if(xline<xlen) xlen=xline;
xline=0;
ylen++;
}
shift%=ylen;//prevent excess of cicles
//------- shifting the numbers
while(shift-->0){
for(i=0;i<xlen;i++) bckp[i]=array[0][i];
for(j=0;j<ylen-1;j++){
for(i=0;i<xlen;i++)
array[j][i]=array[j+1][i];
}
for(i=0;i<xlen;i++)
array[ylen-1][i]=bckp[i];
}
//--------- presenting the result
for(j=0;j<ylen;j++){
for(i=0;i<xlen;i++)
printf("%d\t", array[j][i]);
puts("");
}
getch();
return 0;
}
I hope if you don't mind that I post the already solved solution here... with the input stuff I sugested.