I'm not sure why this code is giving the error message "warning: excess elements in array initializer". I've taken a look at:
http://www.csc.liv.ac.uk/~grant/Teaching/COMP205/string.html
and the example at the bottom seems to be similar to what I'm doing with this code. Can anyone shed any light on the matter. Any help is appreciated, thanks.
The compile error:Code:const int accepted_files = 13; /*compare user file types against file types accepted*/ int file_type_compare(char *file_type) { char *accepted_file_types[accepted_files] = { "mp3", "wma", "wav", "m4a", "ogg", "pmg", "pls", "m3u", "bmp", "gif", "jpg", "png", "tiff" }; int f; for(f = 0; f < accepted_files; ++f) { if (!strcasecmp(*accepted_files[f], *file_type)) /*precaution against the user using mixed or upper case*/ return 0; /*exit, matched a type*/ } die(_("File type \"%s\" matched no type, accepted file types are: put something here\n"), file_type); }
Code:metadata.c:1202: error: variable-sized object may not be initialized metadata.c:1203: warning: excess elements in array initializer metadata.c:1203: warning: (near initialization for ‘accepted_file_types’) metadata.c:1204: warning: excess elements in array initializer metadata.c:1204: warning: (near initialization for ‘accepted_file_types’) metadata.c:1205: warning: excess elements in array initializer metadata.c:1205: warning: (near initialization for ‘accepted_file_types’) metadata.c:1206: warning: excess elements in array initializer metadata.c:1206: warning: (near initialization for ‘accepted_file_types’) metadata.c:1207: warning: excess elements in array initializer metadata.c:1207: warning: (near initialization for ‘accepted_file_types’) metadata.c:1208: warning: excess elements in array initializer metadata.c:1208: warning: (near initialization for ‘accepted_file_types’) metadata.c:1209: warning: excess elements in array initializer metadata.c:1209: warning: (near initialization for ‘accepted_file_types’) metadata.c:1210: warning: excess elements in array initializer metadata.c:1210: warning: (near initialization for ‘accepted_file_types’) metadata.c:1211: warning: excess elements in array initializer metadata.c:1211: warning: (near initialization for ‘accepted_file_types’) metadata.c:1212: warning: excess elements in array initializer metadata.c:1212: warning: (near initialization for ‘accepted_file_types’) metadata.c:1213: warning: excess elements in array initializer metadata.c:1213: warning: (near initialization for ‘accepted_file_types’) metadata.c:1214: warning: excess elements in array initializer metadata.c:1214: warning: (near initialization for ‘accepted_file_types’) metadata.c:1216: warning: excess elements in array initializer metadata.c:1216: warning: (near initialization for ‘accepted_file_types’) metadata.c:1219: error: subscripted value is neither array nor pointer



LinkBack URL
About LinkBacks



. I did originally start using a macro but in Steve Qualline's book "Practical C", he really pushes that the reader should use const over define whenever possible because of immediate syntax checking and scope rules etc. But I'm not sure what to think now.
I used to be an adventurer like you... then I took an arrow to the knee.