What's Wrong with this C Excert

John Campbell jdc at naucse.cse.nau.edu
Sat Aug 4 00:54:34 AEST 1990


>From article <34877 at ut-emx.UUCP:, by ezab066 at ut-emx.UUCP (Albert Wu):
: The following is part of an example I saw on p.301 of Byron S.
: Gottfried's Schaum's Outline Series "Programming with C", copyrighted
: 1990.  It doesn't compile.  Can anyone tell me what's wrong ?  I am
: a total beginner in C.  Pls don't laugh.
: 
: 
: #include <stdio.h>
: 
: #define MAXCOLS 30
: 
: main()
: {
:         int (*a)[MAXCOLS],(*b)[MAXCOLS],(*c)[MAXCOLS];
: 
: 	.........
: 
:         *a = (int*) malloc (rows * ncols * sizeof(nt));
:         *b = (int*) malloc ( nrows * ncols * sizeof(int));
:         *c =(int*) malloc ( nrows * ncols * sizeof(int));
: } 

Well, except for the syntax errors

         *a = (int*) malloc (nrows * ncols * sizeof(int));  /* I presume? */

and the need to define nrows and ncols, what is this supposed

cdecl says:

``declare a as pointer to array 30 of int''

Now trying to malloc at this point sounds like a real mistake.  I
sure wish I knew what the author was thinking of here. 

Anyone else?  (Karl?)
-- 
	John Campbell               jdc at naucse.cse.nau.edu
                                    CAMPBELL at NAUVAX.bitnet
	unix?  Sure send me a dozen, all different colors.



More information about the Comp.lang.c mailing list