title: Sort numbers from a .txt file in C
body: <p>I made a sorting algorithm that works alright when the numbers I need to sort are in an array inside the code, like this:</p>
  
  <pre><code>int sort[] = {16,8,23,4,42,15};
  </code></pre>
  
  <p>But I need the code to sort the numbers from a .txt file, I do know the size of the file (so no need of a <em>sizeof</em> to know how many numbers you need to sort) but the problem is that the numbers in the file are not separated by commas, only spaces, and I don't know how to make my code operate with this list of numbers.</p>
  
  <p>My code is like this, and like I said, it works when the sorting array of numbers is inside the code separated by comas:</p>
  
  <pre><code>int main(){
  
      int temp, size;
      int sort[] = {16,8,23,4,42,15};
      size = sizeof(sort) / sizeof(int);
  
      for(int j = 0; j &lt; size; j++){
          for(int i = 0; i &lt; size; i++){
              if(sort[i] &gt; sort[i+1]){
                  temp = sort[i];
                  sort[i] = sort[i+1];
                  sort[i+1] = temp;
              }
          }
      }
  
      for(int p = 0; p &lt; size; p++){
          printf("%d ", sort[p]);
      }
  }
  </code></pre>
  
  <p>And I also know that to open a file in C the code is something like this:</p>
  
  <pre><code>FILE* f;
  f = fopen("1000.txt", "r");
  if(f == 0){
      printf("Database unavaible or corrupted\n\n");
      exit(1);
  }
  </code></pre>
  
  <p>But I don't know what do next, how do I get this file with unsorted numbers not separated by commas and make my code sort and print them?</p>