'Is it possible to redirect stdout as stdin to same program?

I am writing a filter, and I am exploring an approach to write the program. I was wondering if this is possible: from input in stdin, write to stdout, but redirect this stdout such that the program reads the generated stdout as if it were stdin, again, thus re-processing the data. I do not wish to store the data in a gigantic array -- I wish to do this using streams, solely. Is this even possible? (if not, that's fine too.) Also, a note: I wish to do this only in a single source file of C code.



Solution 1:[1]

Create a pipe. Duplicate the read-end of the pipe as the new STDIN_FILENO, the write-end as STDOUT_FILENO, and you're all set. Everything you now write to stdout will be available on stdin.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Some programmer dude