title: Reading string with spaces from file in c
body: <p>I have a question about reading a string containing spaces from a file.
  Here is my function that reads data from file and writes it to array of structures.
  However, if the input for the first string contains two strings and space between them, then the first string goes to the first parameter and the second string goes to the second parameter.
  How to split the line from a file in such a way that necessary data goes to specified fields of structure?
  Thank you!</p>
  
  <pre><code>void readFileToDiary(FILE* file, drivingDiary* diaryTemp){
  
      int i = 0;
  
      file = fopen("test.txt", "r");
      if (file == NULL)
          printf("\nError opening file!\n");
      else{
          while (!feof(file)){
              fscanf(file, "%s %s %d %s %s %d", diaryTemp[i].locationStart,
                  diaryTemp[i].timeStart, &amp;diaryTemp[i].odometerStart,
                  diaryTemp[i].locationEnd, diaryTemp[i].timeEnd,
                  &amp;diaryTemp[i].odometerEnd);
              i++;
          }
      }
  }
  </code></pre>
  
  <p><strong>Example</strong>
  line inside the file contains:
  some place 13:40 10000 some other place 14:45 10120</p>
  
  <p>So,</p>
  
  <pre><code>      "some place" -&gt; first field of structure,
               13:40 -&gt; second field,
               10000 -&gt; third field,
  "some other place" -&gt; fourth field,
               14:45 -&gt; fifth filed,
               10120 -&gt; sixth field.
  </code></pre>
  
  <p><strong>UPD</strong> Working version is here (without fscanf() check)!</p>
  
  <pre><code>void readFileToDiary(FILE* file, drivingDiary* diary){
  
      int i = 0;
  
      file = fopen("test.txt", "r");
      if (file == NULL)
          printf("\nError opening file!\n");
      else{
          while(fscanf(file, " %[a-zA-Z ]%[0-9:]%d %[a-zA-Z ]%[0-9:]%d%*[\n]",
                  diary[i].locationStart,
                  diary[i].timeStart,
                  &amp;diary[i].odometerStart,
                  diary[i].locationEnd,
                  diary[i].timeEnd,
                  &amp;diary[i].odometerEnd) != EOF)
              i++;        
          }
      }
  }
  </code></pre>