This example should get you close to what you want. More error checking could be added.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_ARRAY_INTS 101
#define MAX_LINE_LENGTH 100
void quicksort(int a[], int left, int right);
int main(int argc, char *argv[])
{
FILE *quick, *fp;
char s[11];
int n;
int x;
int array[MAX_ARRAY_INTS];
if ((fp=fopen(argv[1], "r")) == NULL)
exit(-1);
if ((quick=fopen("sorted.txt", "w")) == NULL)
{
fclose(fp);
exit(-2);
}
n=0;
/* in this case, fgets will read up to 100 characters */
/* per line including the newline character */
while((fgets(s,MAX_LINE_LENGTH,fp)) != NULL)
{
/* overwrite the '\n' with a null character */
s[strlen(s)-1] = '\0';
/* copy the number (changing the string into an integer) into the array */
array[n++] = atoi(s);
}
fclose(fp);
/* do the quicksort */
quicksort(array, 0, n-1) ;
/* save the integers back to the file */
for(x=0; x < n; x++)
{
fprintf(quick,"%d\n",array[x]);
}
fclose(quick);
system("PAUSE");
return 0;
}
/* helper function for quicksort */
int partition( int a[], int l, int r)
{
int pivot, i, j, t;
pivot = a[l];
i = l; j = r+1;
while( 1)
{
do ++i; while( a[i] <= pivot && i <= r );
do --j; while( a[j] > pivot );
if( i >= j ) break;
t = a[i]; a[i] = a[j]; a[j] = t;
}
t = a[l]; a[l] = a[j]; a[j] = t;
return j;
}
/* one of the many quicksorts available on the web */
void quicksort( int a[], int l, int r)
{
int j;
if( l < r )
{
// divide and conquer
j = partition( a, l, r);
quicksort( a, l, j-1);
quicksort( a, j+1, r);
}
}