Re: Pointers and Arrays

From: George Greer (greerga@circlemud.org)
Date: 12/29/99


On Wed, 29 Dec 1999, Warren Robbins wrote:

>5x5
>kkkkk
>kkkmk
>kkmkk
>kmkkk
>kkkkk

You can get PtP work:

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
  int i;
  char **foo = (char **)calloc(5, sizeof(char *));

  for (i = 0; i < 5; i++)
    foo[i] = (char *)calloc(5, sizeof(char));

  printf("%d/%d = %d\n", 1, 3, foo[3][4]);

  return 0;
}

Not particularly easy, but capable.

  Foo is array of pointers to another array of chars:
  0 -> { 0, 1, 2, 3, 4 }
  1 -> { 0, 1, 2, 3, 4 }
  ...etc..

--
George Greer            | CircleMUD Snippets
greerga@circlemud.org   | http://developer.circlemud.org/snippets/


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST