Thread: problem in shifting elements in 2 Dimensional array

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    3

    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. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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?

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    3
    Quote Originally Posted by Adak View Post
    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. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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 },
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    3
    Quote Originally Posted by Salem View Post
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shifting elements in array
    By gamers18 in forum C++ Programming
    Replies: 5
    Last Post: 12-09-2012, 12:28 PM
  2. Deleting and shifting elements in an array
    By sia927777 in forum C Programming
    Replies: 3
    Last Post: 10-13-2010, 01:34 AM
  3. Replies: 9
    Last Post: 05-29-2010, 10:32 AM
  4. Shifting elements in an Array
    By mmarab in forum C Programming
    Replies: 5
    Last Post: 12-10-2007, 12:11 PM
  5. shifting array elements
    By dP munky in forum C Programming
    Replies: 5
    Last Post: 04-17-2003, 01:35 PM