In the following code I am trying for each band to get the number of band members. I've tried a number of things but nothing works. The following looks like it should but doesn't.
If any one could point out what I'm doing wrong it would be greatly appreciated.
numMembers = sizeof(bands[0]) / sizeof(bands[0].members);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
int i;
int j;
int numBands;
int numMembers;
int limit = 4;
struct band {
char name[10];
char *members[20];
};
const struct band bands[] =
{ {"Beatles", {"John", "George", "Paul", "Ringo", "Pete", "George"} },
{"Stones", {"Mick", "Keith", "Bill", "Charlie", "Brian"} },
{"Who", {"Pete", "Roger", "Keith", "John"} },
{"JHE", {"Jimmy", "Noel", "Mitch"} } };
numBands = sizeof(bands) / sizeof(bands[0]);
for ( i = 0; i < numBands; ++i ) {
printf ("%s\n", bands[i].name);
numMembers = sizeof(bands[0]) / sizeof(bands[0].members);
for ( j = 0; j < numMembers; ++j )
printf ("\t%s", bands[i].members[j]);
printf ("\n");
}
return 0;
}
char name[10]for band names, yet a character pointer for band members? I'd expect something likechar *name; char *members[20];orchar name[10]; char members[20][30];