Your assignment start = tmp
only changes the value of start
inside addtoken()
. Since pointers are passed by value, this doesn't alter the pointer start
outside of your function. In order to achieve this, you have to pass a pointer to pointer into your function:
void addtoken(char* word, int counter, struct shellvalue** start, struct shellvalue** current) {
// ..
// replace assignments to start/current with:
*start = tmp
// ..
}
Then, when invoking your function:
struct shellvalue* start;
struct shellvalue* current;
addToken(word, counter, &start, ¤t);
My suggested alternative:
Use a struct to hold both of your pointers, and pass a pointer to it into your function:
struct shellvalue_list {
struct shellvalue* start;
struct shellvalue* end;
};
void addtoken(struct shellvalue_list* list, char* word, int counter) {
// ..
list->start = tmp;
// ..
}
This is a common idiom for object-oriented code in C.