Thread: pointer to the second element of 2-dim array

  1. #1
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246

    pointer to the second element of 2-dim array

    Code:
    char *p;
    
    for ( x = 0; x < 4; x++) {
    p = st[x][1];
    sum += strtol(p, NULL, 10);
     }
    Where st is a 2-dim array that contains something like
    +40
    +50
    +20
    +10
    so i want to strtol and add up everything , that's why i need to skip the '+'.
    i get
    assignment makes pointer from integer without a cast warning and then segfault

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    It would be helpful to see the declaration of 'st', but assuming it is an array of strings, you might want to try this.
    Code:
    p = &st[x][1];
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    ahh, so simple
    thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  2. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  3. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  4. Modify an single passed array element
    By swgh in forum C Programming
    Replies: 3
    Last Post: 08-04-2007, 08:58 AM
  5. Pros pls help, Pointer to array
    By kokopo2 in forum C Programming
    Replies: 7
    Last Post: 08-17-2005, 11:07 AM