By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,497 Members | 2,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,497 IT Pros & Developers. It's quick & easy.

Compiler gives error of missing ']' while it's already there.

P: n/a
Hi! Anybody there who can answer me on my following code:

When I try to compile this code, I get message of a missing ']' on the
line 3 i.e. int a[MAX];, why is this happening

Thanks in anticipation.
VASUDEV MUKHERJEE
#include <stdio.h>
#define MAX 9;
int a[MAX];
int rands=9;
int rand()
{
rands=rands*1103515245 +12345;
return (unsigned int) (rands/65536)%32768;
}
main ()
{
int i,t,x,y;
for(i=0; i<MAX;i++)
{
a[i]=rand();
printf("%d\n", a[i]);
}
}

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

va**************@yahoo.co.uk wrote:
Hi! Anybody there who can answer me on my following code:

When I try to compile this code, I get message of a missing ']' on the
line 3 i.e. int a[MAX];, why is this happening

Thanks in anticipation.
VASUDEV MUKHERJEE
#include <stdio.h>
#define MAX 9;
Think of the implication of the above macro when it is used in the line
below
int a[MAX];


Because of your #define for MAX, the above line will expand to
int a[9;];
before being parsed

Is this what you intend? Is this legal C? (I know the answers - this is
a hint to you that you should look into the questions a bit)

[snip]

- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFDXiKWagVFX4UWr64RAlvbAKDVhYzgX4bEujnIb7R4FY 4tnGmxtQCfalcR
VdLxzmKhtCWh405pQStf18s=
=8DSt
-----END PGP SIGNATURE-----
Nov 15 '05 #2

P: n/a
In article <11********************@f14g2000cwb.googlegroups.c om>,
<va**************@yahoo.co.uk> wrote:
#define MAX 9;
int a[MAX];


This expands to int a[9;];

-- Richard
Nov 15 '05 #3

P: n/a
va**************@yahoo.co.uk wrote:
Hi! Anybody there who can answer me on my following code:

When I try to compile this code, I get message of a missing ']' on the
line 3 i.e. int a[MAX];, why is this happening #include <stdio.h>
#define MAX 9;
int a[MAX];


This expands to
int a[ 9; ];
the error of which is clearer, I think, when written
int a[9;
];
Fix it by losing the semicolon from the #define.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.