0

i have a file "test.txt" which has a list of numbers, like this

1
3    
4
2
3
40
312
53
243
321
423
...etc

I also have an executable which is a sorting algorithm, for example heapsort. when i type ./heapsort it asks me for input untill i press CTRL+D.

How can i make that the ./heapsort input is test.txt?

I have a program "generate". so if i put ./generate 20 | ./heapsort it prints the ordered list. How can i make heapsort read from the text file created with ./generate 20 > test.txt

2 Answers 2

1

Execute you program like this:

./heapsort < test.txt

This redirect the standard input to your file.

Also you may consider change your program to stop asking for inputs after a certain value or when reach the end of the file.

Sign up to request clarification or add additional context in comments.

Comments

1

on Linux\unix : cat test.txt | ./heapsort

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.