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;
}
}
}