Marco Olivares

How to use pointer arrays

Discussion created by Marco Olivares on Apr 1, 2009
Latest reply on Apr 4, 2009 by Marco Olivares
Dear frends Below this lines you´ll find a piece of code that does not work in the lines markedlike this

        *(route[3] + index) = *(y + index);     // No change

My application requires a string table with diferent information in each row, I tried several methods but it doesn´t work, if I assign then directly or if I assign a straigth string it works, but if I assigng from a different variable it doesn´t.

Could you please help me.....


Thanks

Marco Olivares
void main(void) {
char *route[5];
char *y;
char x[5];
char c, index;

// EnableInterrupts; /* enable interrupts */

SOPT_COPE = 0;

    route[0] = "This lines";
    route[1] = "work";
    route[2] = "fine if I";
    route[3] = "assign them";
    route[4] = "directly";


    for (c = 0 ; c < 5 ; c++)
      {
        route[c] = "message";
      }


    y= "FREE";
    for (index = 0 ; index < 4; index ++)
      {
        route[1][index] = y[index];             // No change
        x      [index] = y[index];
      }
      x[index] = '\0';
    
    

    y= "free";
    for (index = 0 ; index < 4; index ++)
      {
        *(route[2] + index) = y[index];         // No change
        *(x       + index) = y[index];
      }
      x[index] = '\0';
    
    

    y= "scal";
    for (index = 0 ; index < 4; index ++)
      {
        *(route[3] + index) = *(y + index);     // No change
        *(x       + index) = *(y + index);
      }
      x[index] = '\0';
    
    


  for(;;) {

 

    }

}

Outcomes