C program runs to avoid re-entering values every time

suppose there is a c program that reads a character and then outputs

scanf("%c", &cha);
printf(%c", cha);

when running in this way, you have to type one character at a time. What I want to achieve is to fix this character in a file so that you don"t have to type it repeatedly each time, as long as you don"t change the above two lines of code.

C
Mar.28,2021

change the input and output stream:

< H1 > include < stdio.h > < / H1 >

int main () {

freopen ("in.txt", "r", stdin);

freopen ("out.txt", "w", stdout);
/ ) the code is written as is, and nothing needs to be modified /

fclose (stdin);
fclose (stdout);
return0;

}


use the input pipe | to resolve this problem.

take the linux system as an example, you can do this

echo -n <> | <>
-sharp 
echo -n hi | cat -
-sharp 
cat <> | <>
Menu