0

Which part of code in find.c is responsible for accepting and dealing with the output from generate.c? How do we know how to prepare the output of one function for it to be usable as an input for the other function?

1 Answer 1

2

Inputting data to programs can be done in many different ways. For example, you may input data from the standard input or stdin (e.g., your keyboard). You may input data from a file or a stream. Or you may input data from another program's output (aka piping).

When you execute ./generate 1000, generate is supposed to generate and output* newline-separated 1000 random ints.

If you rather run ./find 42, you'll be prompted to input a bunch of ints among which you'll search for the value 42 hitting Enter from your keyboard after each value. A newline then is generated and outputted as you hit Enter.

So in both cases, the list inputted to ./find is a list of newline-separated ints (they basically have the same format).

For your question

Which part of code in find.c is responsible for accepting and dealing with the output from generate.c?

It's basically the same part in both cases because using piping is a way of telling your program "I don't want my keyboard to be treated as the stdin, but rather, I'd like you to think of this program's output as the stdin and read data from it instead!"

And since the data are formatted the same way (i.e., they're both lists of newline-separated ints), you have no troubles reading them with the same code!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .