This is one of my first questions so I hope I formulate it well. I checked some other similar questions on StackOverflow but I got no real answers from them. I have the following struct: 

```
struct process {
int priority;
char* path;
char* parameters;
struct process *next;
};

```

I am reading each line from a file and adding the string tokens I get in my struct linked list using a while loop. Here is the adding method:

```
struct process * add(int prio,char* pat, char* par,  struct process *head) {
  struct process *new_node;
  new_node = ( struct process *) malloc(sizeof( struct process));
  new_node->priority = prio;
  new_node->path = pat;
  new_node->parameters = par;
  new_node->next= head;
  head = new_node;
  return head;
}

```

So the main algorithm gets the lines from a file using fgets in a while loop : 

```
while (fgets(line, sizeof(line), file))

```

then I tokenize all the strings I need and use the add method to add them to my linked list. I convert the first string to int to respect the types.

This is my while loop and main algo : 

```
        FILE *file = fopen(filename , "r");
    char line[124];
    // can be put outside and passed as argument.
    struct process *head = ( struct process *)malloc(sizeof(struct process));
    new_node->priority = prio;
    new_node->path = pat;
    new_node->parameters = par;
    new_node->next= head;
    char* priority,*path,*parameters;

    while (fgets(line, sizeof(line), file)) {
         priority=strtok(line," ");             
         // The fix here is the following :
         char *path_token = strtok(NULL, " ");
         path = malloc(strlen(path_token) + 1); 
         strcpy(path, path_token);
         char *par_token = strtok(NULL, "\n");
         parameters = malloc(strlen(par_token) + 1);
         strcpy(parameters, par_token);
         // End of edit Thanks to the answers bellow
         char* junk;
         int p = strtol(priority,&junk,10);
         printf("prio : %d  ",p);
         head = add(p, path, parameters,head);
         printf("\n");
         pront(head);
         printf("\n");
    }
    \\ free the mallocs

```

We notice here that I use the pront() method to print my linked list at every step. I also do it after my while loop. Here is the code for pront():

```
void pront(struct process *head) {
struct process *current_node = head;
while ( current_node != NULL) {
    printf("%d , %s , %s ", current_node->priority, current_node->path, current_node->parameters);
    printf("\n");
    current_node = current_node->next;
}

```

}

the method prints nonsense : 

```
prio : 2  
2 , ./printchars , a 12 b 

prio : 15  
15 , ./printchars , c 23 d 
2 ,  ,  

prio : 7  
7 , ./printchars , e 34 f 
15 , /printchars ,  34 f 
2 , ./printchars , e 34 f 

```

it is supposed to print :

```
7 , ./printchars , e 34 f 
15 , ./printchars , c 23 d 
2 , ./printchars , a 12 b 

```

I am sure that the problem comes from the while loop since when using the adding method outside of the loop and then printing, I get valid results. But as soon as it gets in the loop, the Head linked list doesn't store the values properly! 
Thanks for the help

EDIT : The issue is fixed and the issue was my awfully wrong use of strtok and pointers to char's without malloc. Lesson learned !