int f[2] = { 1, 2, 3 };
int main(){}
#include <stdio.h>
int foo[] = {1,2,3,4,5,6,7,8,0};
int bar[3] = {3,2,1};
#define ArraySize(X) (sizeof(X)/sizeof(X[0]))
int main() {
int i;
printf("%d\n",ArraySize(foo));
printf("%d\n",ArraySize(bar));
for (i=0;i<ArraySize(foo);i++)
printf("%d\n",i);
return 0;
}
const struct skill_type skill_table [MAX_SKILL] = {…}
but also
const struct item_type item_table [] =
{
{ ITEM_LIGHT, "light" },
…,
{ 0, NULL }
};/* merc.h */
#include <stdio.h>
typedef int sh_int;
#define MAX_CLASS 4
#define MAX_IN_GROUP 15
#define ArraySize(X) (sizeof(X)/sizeof(X[0]))
struct group_type
{
char * name;
sh_int rating[MAX_CLASS];
char * spells[MAX_IN_GROUP];
};
extern const struct group_type group_table[];
extern const int MAX_GROUP;
/* const.c */
#include "merc.h"
const struct group_type group_table [] =
{
{
"rom basics", { 0, 0, 0, 0 },
{ "scrolls", "staves", "wands", "recall" }
},
{
"mage basics", { 0, -1, -1, -1 },
{ "dagger" }
},
{
"transportation", { 4, 4, 8, 9 },
{ "fly", "gate", "nexus", "pass door", "portal", "summon", "teleport",
"word of recall" }
},
{
"weather", { 4, 4, 8, 8 },
{ "call lightning", "control weather", "faerie fire", "faerie fog",
"lightning bolt" }
}
};
int const MAX_GROUP = ArraySize(group_table);
/* somewhere.c */
#include <stdio.h>
#include "merc.h"
int main() {
int i;
for (i=0;i<MAX_GROUP;i++) {
printf("%d - %s\n",i, group_table[i].name);
}
return 0;
}
I'm getting an excessive elements in array initializer error and I'm having problems finding the error (might be sleepiness). Can anyone help please?
{ "conjuration", { 5, 5, -1, -1 },{ "continual light", "create food", "create rose", "create spring", "create water",
"cure blindness", "cure critical", "cure disease", "cure light", "cure poison",
"cure serious", "gate", "heal", "mass healing", "nexus",
"portal", "summon", "teleport", "word of recall" }
},
The exact error message is:
And what exactly does that error message mean?
Thank you,
Arholly