#include <stdio.h>
typedef struct
{
int num ;
} NUMBER ;
int main(void)
{
struct NUMBER array[99999];
return 0;
}
I'm getting a compile error:
error: array type has incomplete element type
I believe the problem is that I'm declaring the array of struct incorrectly. It seems like that's how you declare it when I looked it up.
struct NUMBER array[99999];
should be
NUMBER array[99999];
because you already typedef
ed your struct.
EDIT: As OP is claiming that what I suggested him is not working, I compiled this test code and it is working fine:
#include <stdio.h>
typedef struct
{
int num ;
} NUMBER ;
int main(void)
{
NUMBER array[99999];
array[0].num = 10;
printf("%d", array[0].num);
return 0;
}
See the running code.
You have
typedef struct
{
int num ;
} NUMBER ;
which is a shorthand for
struct anonymous_struct1
{
int num ;
};
typedef struct anonymous_struct1 NUMBER ;
You have now two equivalent types:
struct anonymous_struct1
NUMBER
You can use them both, but anonymous_struct1
is in the struct
namespace and must always be preceded with struct
in order to be used. (That is one major difference between C and C++.)
So either you just do
NUMBER array[99999];
or you define
typedef struct number
{
int num ;
} NUMBER ;
or simply
struct number
{
int num ;
};
and then do
struct number array[99999];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With