struct {int **i}; problem

Sven Heinicke sven at cs.widener.edu
Sun Mar 24 07:34:14 AEST 1991


I got a little double integer pointer in a structure problem while in a
subprogram problem.  I think I have got everyting but one line down but 
I am not 100% sure about the malloc() line either.  Here is the extract
of the code I am working on:

.
.
.
struct imatrix {
  char **board;
  int size;
};
typedef struct imatrix iMATRIX;

main()
{
  int l;
  iMATRIX playing;
.
.
.
  /*
   * here are the three malloc() lines I am
   * not sure work right but I think do.
   * playing.size is picked bye the user.
   */
  playing.board = (int**)malloc(sizeof(int *) * playing.size * playing.size); 
  for(l = 0;l < playing.size * playing.size;l++)
    *(playing.board) = (int*)malloc(sizeof(int));

  reset(&playing);
.
.
.
}

reset(matrix)
     iMATRIX *matrix;
{
  int x,y;

  for(x = 0;x < matrix->size;x++)
    for(y = 0;y < matrix->size;y++)
      (*(matrix->board+x)+y) = x * matrix->size + y + 1;
  /*
   * This in the line that I got confused about, 
   * it don't compile.  In gnu c it gets the error:
   *           invalid lvalue in assigment
   *
   * could somebody tell me what line to use?
   *
   */
}

-- 
sven at cs.widener.edu                                  Widener CS system manager
Sven Mike Heinicke                                          and Student
(pssmheinicke at cyber.widener.edu (if you must))



More information about the Comp.lang.c mailing list