# Thread: problem in shifting elements in 2 Dimensional array

1. ## problem in shifting elements in 2 Dimensional array

My name is Biswanath Chowdhury. I have stuck in a problem in C-language and need help regarding this.

I am inserting elements from two files into 2-D arrays.

Suppose I have generated this kind of code to create 2-D array:

Code:
``` main() {
int counter;

int divide=5, m1=0, l1=20, window=20;

for(counter=0;counter<divide;counter++){

for(i=m1,j=0;i<l1;i++,j++){

windata[counter][j]=database[i];

winquery[counter][j]=input[i];
}
m1=i;

l1=window1+l1;}

}```
Now after generating 2D array, if I want to shift last 2 elements from windata[counter] or winquery[counter] where counter=0 to the beginning of counter 1 and subsequently last two from counter 1 to counter 2 in this fashion, how can I do that. Please help me regarding this.

2. Welcome to the forum, Biswanath!

Show a simple example of the before and after of what you want, so I'm clear on it. Are these 2D arrays strings or ints?

Welcome to the forum, Biswanath!

Show a simple example of the before and after of what you want, so I'm clear on it. Are these 2D arrays strings or ints?
These are 2D arrays of strings. I am doing research so the program having so many things, so I can not make it clear to you what I want to do before and after this. But I can give you a simple example as below.
Suppose first array contains a,b,c,d,e
second array contains f,g,h,i,j
third array contains k,l,m,n,o.

now I want to shift 'd' and 'e' of the first array to the beginning of second array and 'i' and 'j' from second array to the third so the final result would be
first array will contain : a,b,c
second array will contain: d,e,f,g,h
third array will contain : i,j,k,l,m,n,o

4. It can't really be an array, if all the rows end up being different lengths.

It seems to me that all you have is a single array containing say
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o

and another array such as
Code:
```struct foo {
int start;
int len;
} grid[3] = {
{ 0, 5 },
{ 5, 5 },
{ 10, 5 },
};```
Which after a bit of fiddling with the numbers becomes
Code:
```  { 0, 3 },
{ 3, 5 },
{ 8, 7 },```

5. Originally Posted by Salem
It can't really be an array, if all the rows end up being different lengths.

It seems to me that all you have is a single array containing say
a,b,c,d,e,f,g,h,i,j,k,l,m,n,o

and another array such as
Code:
```struct foo {
int start;
int len;
} grid[3] = {
{ 0, 5 },
{ 5, 5 },
{ 10, 5 },
};```
Which after a bit of fiddling with the numbers becomes
Code:
```  { 0, 3 },
{ 3, 5 },
{ 8, 7 },```
I can't understand your reply. I have mentioned the code of my program before and told what I exactly want to do.