Initilization of global structures
Barton E. Schaefer
schaefer at ogicse.ogi.edu
Thu May 3 02:53:53 AEST 1990
In article <9005020423.AA05715 at en.ecn.purdue.edu> wscott at EN.ECN.PURDUE.EDU (Wayne H Scott) writes:
}
} I am having some problems with a program I am writing. This might be very
} simple but I can't figure it out.
}
} [file=globals.c]
} #define MAXNUM 5
} struct weapon {
} char *name;
} /* etc */
} };
} struct weapon wstats[] = { "knife", "sword" /* etc ... */ };
This is not doing what you think it's doing. The outer set of { } defines
the initializer for the array. You need an additional set of { } for each
structure-typed element. Try:
struct weapon wstats[] = {
{ "knife", /*etc*/ }, { "sword", /*etc*/ }, /* etc ... */
};
--
Bart Schaefer | The Ultimate Scheme: [apologies to Wadler]
| call-cc (lambda (answer)
schaefer at cse.ogi.edu | (/ universe (if (= life 0) (answer 42) life)))
More information about the Comp.lang.c
mailing list