How to change my bubble sort program to sort from a text file?

I am new to programming and for a class project, we are to create a bubble sort program. The program works right now by asking the user to enter in the number of integers and then the integers themselves. I am wondering how I can change this so that the program just accepts text files instead? For example, the user would enter at the terminal
"./bubblesort 20 < example.txt" meaning you'd want to read the first 20 numbers in whatever text file??
Thanks!


for (i=0; i < n; i++)
scanf("%d", &array[i]);

for (i=0; i < (n-1); i++)
{
for (j=0; j < n - i - 1; j++)
{
if(array[j] > array[j+1])
{
swap = array[j];
array[j] = array[j+1];
array[j+1] = swap;
}
}
}


Last edited on
Please do not post more than once:
http://www.cplusplus.com/forum/beginner/158928/
Topic archived. No new replies allowed.