When you pipe a.out into gs, a.out sends all it's output to gs and stops running. I don't think you can pipe one line at a time.
When I use C, I use it in a combination with Lua language, because Lua is written as a C library and work perfectly together with C. Lua is designed to work with large amount of text and data and can be embedded in C and C++ programs. With Lua you would have
os.execute() to call gs after each line. Free Lua book from Lua's author:
https://www.lua.org/pil/contents.html