I have written some code to help me deliminate dashes in my program for a larger linked list but when I call the class my code gets stuck on the deliminator loop and does not die. I cant even kill it with the kill command I have to open a new ssh client
int deliminator(char word[], struct node *root){
struct node *start = (struct node*) malloc(sizeof(struct node));
struct node *trav = (struct node*) malloc(sizeof(struct node));
start->next= trav;
trav->prev = start;
char *token;
token = strtok(word,"-");
while(token){
/* this loop is broken */
printf("%s",token);
struct node *curr = (struct node*) malloc(sizeof(struct node));
strcpy(curr->set, token);
trav->next = curr;
curr->prev = trav;
trav = trav->next;
token = strtok(NULL,"-");
};
root->next = start;
return(0);
};
Also when I try to run the strtok improperly by looping with token = strtok(token,"-"); it gets stuck on the first token. I can't seem to find the problem, a friend of mine suggested that it had to do with the linked list nodes but i removed them and I had the same issue.
I call the deliminator class in this code snippit.
int main(int argc, char *argv[]){
struct node *root = (struct node*) malloc(sizeof(struct node));
struct node *trav = (struct node*) malloc(sizeof(struct node));
root->next = trav;
if(argc == 2){
/*only one giant string*/
deliminator(argv[1],root);
while(root->next!= NULL){
printf("%s",root->set);
};