0

guys.

In pset3 we have a find.c which generates a haystack. When you run ./find, then it just keep asking for integer unless you press Ctrl+D (call a EOF). But we didn't even need to define such a EOF in generate.c in order to run a pipeline ./generate 1000 50 | ./find 127 . Why? I am really confused about this thing.

0

The EOF is a character (usually meant to signal if there aren't characters/bytes in a file left). You trigger this character by pressing Ctrl+D together, not as other characters whereby you just press one button (e.g. 'A'). This character is already defined just like all other characters, that's why you don't need to define it, as you don't need to define the letters 'A' or 'B' for example. In the program input, by clicking Ctrl+D you signal to the program that there isn't any input to give anymore (end of input, as you might want to visualize this). Wikipedia says this:

In computing, end-of-file (commonly abbreviated EOF[1]) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

3
  • But if we don't define EOF in generate.c, how can we tell the programm find.c that this is the end of file? I mean, if we use pipeline command ./generate 1000 50 | ./find 127 – Ka Lok Kam Dec 29 '16 at 16:06
  • You are generating with generate.c 'x-values' (I don't remember if it was 1000 or 50 values). We then pass that as input to find.c, find.c stops executing when all of the values are passed. You don't define EOF since it is defined automatically for you. It's like when you open Microsoft Word, you type an essay of say, 250 characters. Inside your Word document, the character number 251 is automatically the EOF (and you didn't define it, nor did you type 'EOF'). – Kobrajunior Dec 29 '16 at 17:16
  • Thank you for your answer, now I understand this concept better. – Ka Lok Kam Dec 30 '16 at 23:00

You must log in to answer this question.

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