using pointers to fill arrays

HI!
i am having trouble understanding how to use pointers with arrays. more specifically how to use a pointer to one array to fill a second array. assume i have a 144 bit array, rs_codewords, that has its first 72 positions filled with data and the second 72 positions filled with parity bits. using a pointer to rs_codewords[], i have to put what is in this array into another array, recd[], rearranged so that the first 12 positions will be data, the next 12 positions are parity bits (to create a 24 bit codeword); and so on like that for the rest of the 5 codewords. below is my code so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define mm  6           /* RS code over GF(2**6)  */
#define nn  24          /* nn=2**mm -1   length of codeword */
#define tt  6           /* number of errors that can be corrected */
#define kk  12          /* kk = nn-2*tt  */


  int pp [mm+1] = { 1, 1, 0, 0, 0, 0, 1 } ; /* specify irreducible polynomial coeffts */
  int alpha_to [nn+1], index_of [nn+1], gg [nn-kk+1] ;
  int recd [nn], data [kk], bb [nn-kk] ;


// 1st parameter is pointer to 144 bit array filled by the hamming decode
// 2nd parameter is pointer to 72 bit array filled by this decoder to be used later
void
ldu1::decode_reed_solomon(uint16_t *rs_codewords, uint16_t *decoded_lcw) 
{
  
  generate_gf(  ) ;
  gen_poly(  ) ;

  for(int index = 0; index < 6; index++)
  {
    /* 
       takes the 144 bits in rs_codewords array filled by the hamming decoder       
       the first 72 bits are data, the last 72 bits are parity
       there are 6 24-bit codewords, first 12 bits are data, last 12 bits are parity bits 
    */
        // create the codewords, put data and parity in right places
    int i;
    for (i=0; i<nn-kk; i++)  recd[i] = rs_codewords[i*index+kk] ;  // 72 parity bits, should start taking values from oridals 72-143
    for (i=0; i<kk; i++) recd[i+nn-kk] = rs_codewords[i*index] ;   // 72 bits data payload, should start taking values from oridals 0-71

    //  put recd[i] into index form;  should 24-bit codeword
    for (i=0; i<nn; i++)                  
       recd[i] = index_of[recd[i]] ;         

                                                  
    decode_rs();  // recd[] is returned in polynomial form, should be 12-bits of data

    // need to store the 6 corrected 12-bit arrays recd[] into single 72 bit array
    for(i=nn-kk; i < nn; i++)
    {
      decoded_lcw[i - (nn-kk) + index*(nn-kk)] = recd[i];  
    }
  }
}

similarly, i am concerned that memcopy() will not work for the purpose of filling an array with the values in another array via pointer:
1
2
3
4
5
6
7
8
9
10
void
ldu1::decode_hamming( uint16_t *encoded_lcw, uint16_t *rs_codewords ) 
{
    //  get 24 10-bit codewords out of 240 bit encoded_lcw array
    for (int index = 0; index < 24; index++)
    {
        int edata[10] = {0};
        
        //  put each 10 bit coeword in edata[] for decoding
        memcpy(edata, (encoded_lcw+10*index), 10);   // will this work?? pointer points to only encoded_lcw[0]?? 

any help will much appreciated. Thanks in advance.
Last edited on
Topic archived. No new replies allowed.