title: how to rewind to the beginning of a line while reading from a file. c
body: <p>other than counting how many spaces i moved. is there a simple way to get the buffer back to the beginning of a line for reading? am trying to read in strings and then go back to read a different string and numbers. its not in order so i have to go back and look for them specifically. how do i do it.</p>
  
  <p>i use <code>rewind(fp);</code> but that goes back to the beginning of the file.</p>
  
  <p>also am trying to read in integers after the strings. the problem is its hard to read in double, triple digit numbers. i was able to do. but as you see the function down there is a mess. is there an easier way to read multi-digit integers;</p>
  
  <pre><code>void get_total(FILE*fp, int* ptotal, int* pscores, int* pnum_quiz){
  
      char c;
  
      int i = 0;
  
      int total=0;
  
      int digits; 
      int first, second, third;
  
      *pnum_quiz = 0;
  
      int number_of_conversions;
  
      number_of_conversions = fscanf(fp, "%c", &amp;c);
  
      while (isdigit(c) || isspace(c) &amp;&amp; c !='\n' &amp;&amp; c !=NULL &amp;&amp; number_of_conversions!=0 &amp;&amp; number_of_conversions !=EOF){
  
  
          if (isspace(c)){
              number_of_conversions = fscanf(fp, "%c", &amp;c);
  
          }
  
          else if (isdigit(c)){
              first = c - '0'; // convert a character integer to integer
  
              *(pscores + i) = first;
              i++;
  
              number_of_conversions = fscanf(fp, "%c", &amp;c);
  
              digits = 1;
  
              if (isdigit(c)){
  
                  second = c - '0';
  
                  *(pscores + i) = second;
  
                  i++;
  
                  number_of_conversions = fscanf(fp, "%c", &amp;c);
  
                  digits = 2;
  
                  if (isdigit(c)){
  
                      third = c - '0';
  
                      *(pscores + i) = third;
                      i++;
  
                      digits = 3;
                  }
                  else{
                      fseek(fp, -1, SEEK_CUR);
                      *(pscores + i) = -1;
                      i++;
                  }
  
  
              }
              else{
                  fseek(fp, -1, SEEK_CUR);
                  *(pscores + i) = -1;
                  i++;
                  *(pscores + i) = -1;
                  i++;
              }
  
              if (digits==3){
                  total = total + (first * 100) + (second * 10) + third;
              }
              else if (digits==2){
                  total = total + (first * 10) + second;
              }
              else {
                  total = total + first;
              }
  
  
              number_of_conversions = fscanf(fp, "%c", &amp;c);
  
  
  
          } 
  
          number_of_conversions = fscanf(fp, "%c", &amp;c);
  
          *pnum_quiz = *pnum_quiz + 1;
      }
  
      *ptotal = total;
  
  }
  </code></pre>