Interactive scanf using pipe

214 views Asked by At

I try to read a value from console in unix using pipe

exmpl.cpp:

#include <stdio.h>
int main()
{
 int d;
 scanf("%d",&d);
 printf("d=%d",d);
 return 0;
]

So, when i use

./a.out < tmp

I get the number from tmp immidiately, but i want to get number from console

Also, I tried to use

fscanf(stdin, "%d",&d); 

but it didn't help

1

There are 1 answers

2
domen On

You can't really do that. With < you've changed the stdin of the program, therefore you can't use stdin for user interaction anymore.

Consider using tmp file as an argument.