title: How to read characters from a file until a space and store that as one string (c)?
body: <p>I need to read all the information from a line in a file before a space and store it as a string, how do I do that?</p>
  
  <p>File example:</p>
  
  <pre><code>Biology A 4.0
  Tennis B 1.0
  </code></pre>
  
  <p>etc (I need the letter and number later and I know how to store them fine, just the dang string is giving me trouble) </p>
  
  <p>So far I have</p>
  
  <pre><code>int main (void)
  {
      FILE* grades;
      char className[10];
      char currChar;
      int i = 0;
  
      grades = fopen("grades.txt", "r");
      if (fgetc(grades) != ' ')
      {
          currChar = fgetc(grades);
          className[i] = currChar;
          i++;
      } 
  
      /* what I want to happen here: if a character is not a space, it is
          appended to className. I thought if i was the position in the array,
          I could add in one character at a time
      */
      printf("%s", className); // check to make sure it worked
  }
  </code></pre>
  
  <p>what the result is: the symbol that looks like a ? in a hexagon</p>
  
  <p>Thanks for any help, I'm open to trying other ways too. I tried using fgets with the length i equal to the number of characters before a space found in a previous while loop, but that printed the part directly after the area I wanted.</p>