title: Reading from a file based on space delimiter
body: <p>I have text file that contains 4 lines of data. Each line is as follows</p>
  
  <pre><code>Candies 2
  Cookies -4
  Soda 5
  Milk 8
  </code></pre>
  
  <p>I have to read the the values (2,-4,5,8) in a C function and store them in a variable.</p>
  
  <p>I have written the following code and I'm stuck at the point where I've indicated by XXXXXX. I'm not sure what exactly goes in there and after that. Appreciate your help.</p>
  
  <pre><code>  void function()
    {
      int count=0,value[4],length=0;
  
      FILE *fp;
  
      fp = fopen("file.txt","r");
  
      if (fp == NULL)
      {
        fprintf(stderr, "Can't open file !\n");
        exit(1);  
      }
  
       char line[100];
          for (count = 0; count &lt; 4; count++)
          {      
              if (fgets(line,sizeof(line),fp)==NULL)
          break;
  
          else 
      {  
  
         while(fp!="" &amp;&amp; length&lt;strlen(line))
         {
         fp++;length++
         }
  
         if(fp == "") 
           value[count]= XXXXXXXX;
      }  
  } 
  </code></pre>