Changing stdin from file redirection to console input

Hi

I am doing file redirection at console for use by my binary.

%console%> bin &lt inputfile

After reading in the entire file, I want my program to continue taking input from the console. So essentially I want to redirect stdin back to console. But I cant figure out how to do it.

I am using GNU compiler on Linux and Solaris. Can anyone help me in this regard.

Thanx
Nauman

I'm not exactly clear what
you are trying to do but
after your done reading the file,
try closing all fd's

// assuming you have no more that 10 files open
for(i = 0; i < 10; i++)
{
if(close(i) < 0)
break;
}

...then open a new file. The fd will be 0 (stdin).

I am not opening any file in my program. The file is being redirected to stdin by the OS.

bin &lt inputfile

I am using gets() to read, which not to mention read from the stdin. After I am finished reading the file, I want gets() to continue reading from console input.

Are u implying that file redirection causes a fd attached to stdin. If so when I reopen the fd, what argument should I give it, to attach it to console input.

I am going to try it next anyway and see what happens.

Thanx

Nauman

When a program is loaded by the OS,
it is automatically given 3 open files...

stdin -> fd=0
stdout -> fd=1
stderr -> fd=2

By closing all fd's you guarantee that
the next file you open...

open(...)

...will be assigned fd 0

Thanx. Ur comments really helped. Besides I also got to know how OS works and how to redirect stdin.

Thanx and regards
Nauman