The problem seems to be that "aString" is the same memory location for every iteration of the loop, so all items "exampleStruct[i].name" are pointing to the same place, which ends up having the last value of the iteration loop.
You need to use different memory location to store each of the result-strings for every iteration.
There are several alternatives to resolve this situation.
You can use strdup() which will duplicate the result string in a new "malloc-ed" memory location. This is not standard C function as described here (strdup() - what does it do in C?).
Also you have to remember to free() this memory after you finish using it.
[There is also a strdupa() function but it is less portable than strdup() as described in this question strdupa() in C - Dangers and Duplicates ]
If you have already reserved memory locations for the result-strings you can use strcpy(). This is ANSI C standard.
You could also call malloc() yourself before copying the string using memcpy() like this.
struct Example {
char* name;
};
struct Example exampleStruct[5];
int i;
for (i = 0; i < 5; i++) {
//Pretend aString is a different random string each loop
char* exampleString = strtok(aString, " ");
size_t slen = strlen(exampleString) + 1; /* the +1 is to include the copy of the NULL character */
char* tstr = malloc(slen);
memcpy(tstr, exampleString, slen);
exampleStruct[i].name = tstr;
}
Remember you have safe versions of these functions: strncpy() and strndup().