I have the following C struct:
typedef struct {
    char *name;
    int nfollowers;
    char *followers[];
} User;
There's a point in my code where I have to allocate memory for the last variable of the struct (followers) and I'm having issues on it.
I have tried this:
users[nusers].followers = (char **) realloc(users[nusers].followers, sizeof(char));
or this
users[nusers].followers = (char **) realloc(users[nusers].followers, sizeof(char *));
but the output I get after compiling is the following:
error: invalid use of flexible array member
How can I properly do this?
EDIT
Example of how my C file is structured:
 User *users;
 int i=0, n, nusers=0;
 char aux, *str;
 
 fd_in = open(argv[1], O_RDONLY);
 
 if (fd_in >= 0) {
    users = (User *) malloc(sizeof(User));
    while (aux!='&') {
        users[nusers].followers = (char **) realloc(users[nusers].followers, sizeof(char)); //Issue
          while (aux != '#') {
              ...
          }
      }
  }

char** followers. Where's the originalmallocorcalloc?users.followersa flexible array member? Or was it supposed to be a normal array member?reallocacts likemaillocif the pointer isNULL. When working with a FAM, you allocate for the struct and FAM at the same time. Currently your FAM is an array of pointers tochar. So you need to know how many pointers you want when you allocate for your struct. For example, if you want 10 pointers, you would allocateUser *users = calloc (1, sizeof *users + 10 * sizeof *users->followers);There can only be one FAM, so you cannot have an array ofUser, and theUserstuct cannot be nested within another struct.malloc, it is unnecessary. See: Do I cast the result of malloc?