1

This question is from the book Programming Pearls 2nd Ed., Column 2, p.20. It's a simple C program that uses a sign.c and squash.c files to sort and squash anagrams (display each group of anagrams on separate lines).

To test the program, I have to run the following line in the terminal:

sign <dictionary | sort | squash > gramlist

instead of using a file/dictionary, I wanted to enter a small list of words/anagrams and see if the program sorts and squashes the anagrams appropriately.

For example, entering the following words as the input

mile lime rot tor break

should give me the following output:

break
lime mile
rot tor

My question : what's the syntax to enter those words as the input? Neither of these works:

sign <"mile, lime, rot, tor, break" | sort | squash > output.txt
sign <"mile lime rot tor break" | sort | squash > output.txt
sign <'mile lime rot tor break' | sort | squash > output.txt
sign <'mile, lime, rot, tor, break' | sort | squash > output.txt
sign <mile, lime, rot, tor, break | sort | squash > output.txt
sign <mile lime rot tor break | sort | squash > output.txt

The complete code for sign.c and squash.c is here

1 Answer 1

4

So you know, anything you write with < is going to redirect a file into your program. Since you want to input a string directly, you need something else. Try:

sign <<< "mile lime rot tor break" | sort | squash > output.txt

or:

echo "mile lime rot tor break" | sign | sort | squash > output.txt
Sign up to request clarification or add additional context in comments.

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.