title: Adding a struct to linkedlist in c
body: <p>I'm trying to add <code>Process</code>-structs to a linked list. Their definitions are as follows.</p>
  
  <pre><code>typedef struct {
      char name[2];
      int duration;
      int priority;
      int arrival;
  } Process;
  
  typedef struct {
      Process p;
      struct LinklistNode* next;
  } LinklistNode;
  </code></pre>
  
  <p>The function that I'm using to create the process looks like this.</p>
  
  <pre><code>Process makeProcess(char nameIn[2], int durationIn, int priorityIn, int arrivalIn){
      Process p = (Process*) malloc(sizeof(Process)); //getting an error
      p-&gt;name = nameIn;
      p-&gt;duration = durationIn;
      p-&gt;arrival = arrivalIn;
      p-&gt;priority = priorityIn;
  }
  </code></pre>
  
  <p>I'm not sure that I'm doing that part right, and I'm also not sure that I should be returning a process or have it void, as this process "should" go into the linked list.</p>
  
  <p>My code for creating a linked list node is as follows:</p>
  
  <pre><code>LinklistNode* create_linklist_node(Process pIn) {
      LinklistNode* node = (LinklistNode*) malloc(sizeof(LinklistNode));
      node-&gt;p = pIn;
      node-&gt;next = NULL;
      return node;
  }
  </code></pre>
  
  <p>For a bit more context I'll be calling these functions in <code>main()</code> where I've tokenized a string from a file I'm reading from.  I'm wondering the best way to make the <code>Process</code> struct. Right now I have this:</p>
  
  <pre><code>while(!feof(fPointer)){
      //the i counter is for the first line in the text file which I want to skip
      while ((fgets(singleLine, 1500, fPointer) != NULL) &amp;&amp; !(i == 0)){
          char *token = strtok (singleLine, delimit);
  
          while(token != NULL){
              printf(" %s\n", token);
              token = strtok(NULL, delimit);
  
  
  
          }
  
      }
      i++;
  }
  </code></pre>
  
  <p>Bit of a long question but any references or additional information is always appreciated.  Let me know if you have additional questions or need more info on what I'm doing or why I'm doing something. Or if you can find an example of something similar, that would be greatly appreciated as I haven't had much luck with that so far.</p>
  
  <p>Thanks</p>