How to concatenate array index for same elements for specified range?

This is a discussion on How to concatenate array index for same elements for specified range? within the C Programming forums, part of the General Programming Boards category; Hi sorry i am posting the same problem again. Actually i found some mistakes in my post. So here is ...

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

    How to concatenate array index for same elements for specified range?

    Hi
    sorry i am posting the same problem again. Actually i found some mistakes in my post. So here is the modified version. I want to concatenate the indexes of elements of array that has the same value for specific range.In my case the range is 4
    My code is:

    Code:
    int element[8]={2,2,0,3,3,0,1,2}; col=4; int rr; int qq=0; for (rr=0; rr<col;rr++){ join_tmp[qq]=rr; while ((element[rr]== element[rr+1]) ) { join_tmp[qq]= concatenate(rr+1, join_tmp[qq]); printf("%d\n",join_tmp[qq]); rr++; } qq++; }
    Code:
    //FUNCTION TO CONCATENATE INTEGER VALUES OF SAME GROUP IN A COLUMN unsigned concatenate(unsigned x, unsigned y) { unsigned pow = 10; while(y >= pow) pow *= 10; return x * pow + y; }
    Code:
    I want input like
    10
    2
    3
    Instead i get
    10
    2
    34
    


    how can i fix it so it will only iterate to the specific range?
    Last edited by gevni; 04-22-2013 at 05:26 AM.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    You need to stop the while loop when "rr" reaches "col".

    Awful variable names BTW.

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    31
    Thanks i get it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-19-2013, 02:14 PM
  2. How to get index of structure elements?
    By gevni in forum C Programming
    Replies: 7
    Last Post: 04-09-2013, 02:33 PM
  3. Replies: 8
    Last Post: 04-04-2012, 09:03 PM
  4. Replies: 15
    Last Post: 07-24-2008, 03:03 AM
  5. accessing user entered array elements by index?
    By richdb in forum C Programming
    Replies: 10
    Last Post: 04-08-2006, 11:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21