I want to directly push a character array into the standard input stream stdin
, but cannot think of a syntax that works. The closest I can think of is
freopen("input.txt", "r", stdin);
which reads the contents from a file "input.txt" into the FILE pointer stdin. But I don't like this approach because 1) it relies on creating an additional file, 2) I have to worry about creating one file for each of such requests, which can turn into a ton of txt files in a folder just for this simple purpose of assigning some character array to stdin.
Is there a better, more elegant way of doing this?