Code:
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(void) {
        const char* line = "user1,user2,&,user4 group1,group2,group3 string1 string2 string3";
        const char* user = "user3";
        const char* end = line;
        const char* start;
        char* field;
        size_t len;

        while (isspace(*end)) ++end;
        start = end;
        while (*end != '\0' && !isspace(*end)) ++end;
        len = end - start;
        field = malloc(len + 1);
        sprintf(field, "%.*s", len, start);
        printf("%s\n", field);
        free((void*)field);
}
At the moment, the above program outputs "user1,user2,&,user4." How can I modify it so that it replaces & with char* user (preferably in the while block) without using realloc? Or if it cannot work without realloc, how can I correctly use it in this situation? The output should look like "user1,user2,user3,user4." Thanks in advance for any help.