title: How can i sort records in a text file in C?
body: <p>I created a program supposed to take inputs from the user and write them on a text file. Now i'm making another program to read those records from the file and sort them.</p>
  
  <p>So i have, for example:</p>
  
  <pre><code>User three; Test three; 30
  User one; Test; 51
  User two; Test two; 40
  </code></pre>
  
  <p>The program should sort these records according to the number at the end of it, so it should be:</p>
  
  <pre><code>User one; Test; 51
  User two; Test two; 40
  User three; Test three; 30
  </code></pre>
  
  <p>This is my current effort, basically i created a <code>char one</code> variable which will store the data given from <code>fgets</code> and print it. Two problems: <code>char one</code> has a fixed variable (255), so if the record will be longer than 255, there will be an error.</p>
  
  <p>The second problem is that i don't know how to treat each record of the file has a variable, i can print the whole file but i don't know how to compare the data according to the last  number, any advice? I was looking forward to using a bubble sort for it.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
  
      char one[255];
  
      FILE * fpointer = fopen("record.txt", "r");
  
      while (!feof (fpointer) ) {
      fgets(one, 255, fpointer);
      printf("%s", one);
      }
  
      fclose(fpointer);
      return 0;
  
  }
  </code></pre>