<div dir="ltr">FYI...I tried using this and didn&#39;t get it to work but there is a way to do this using freopen, dup, dup2 by saving stdin,stdout then redirecting to dev/tty and then restoring them back. This method seems to work the best for me. Thanks.<div>
<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Nov 28, 2013 at 5:02 AM, kwang9 <span dir="ltr">&lt;<a href="mailto:kwang9@stevens.edu" target="_blank">kwang9@stevens.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Shen,<br>
<br>
while (read(...)) ;                   // read all content from stdin, it fails when file is BIG<br>
freopen(&quot;/dev/tty&quot;, &quot;r&quot;, stdin);      // redirect stdin back to terminal<br>
printf(&quot;Input phrase:\n&quot;);            // prompting<br>
read(...);<br>
<br>
Anyway there&#39;s another work around:<br>
<br>
FILE *phr_fd=fopen(&quot;/dev/tty&quot;, &quot;r&quot;);  // get terminal&#39;s fd first<br>
printf(&quot;Input phrase:\n&quot;);            // prompting<br>
read(...);<br>
fclose(phr_fd);<br>
while (read(...)) {                   // do work now<br>
    /* deal line by line */<br>
}<br>
<br>
在 2013-11-28 03:39,Hongyi Shen 写道:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
This problem has frustrated me for hours.<br>
<br>
In the requirement of HW5,<br>
<br>
echo &quot;Kookaburra has left the tree&quot; | aed -e | aed -d<br>
<br>
Then we want user to input passphrase, but scanf will<br>
read &quot;Kookaburra has left the tree&quot; first, instead of waiting for<br>
user&#39;s passphrase.<br>
<br>
(When use pipe, isatty might be a way)<br>
<br>
Thank you all, enjoy the holiday.<br>
<br></div></div>
______________________________<u></u>_________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu" target="_blank">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/<u></u>mailman/listinfo/cs631apue</a><br>
</blockquote>
______________________________<u></u>_________________<br>
cs631apue mailing list<br>
<a href="mailto:cs631apue@lists.stevens.edu" target="_blank">cs631apue@lists.stevens.edu</a><br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue" target="_blank">https://lists.stevens.edu/<u></u>mailman/listinfo/cs631apue</a><br>
</blockquote></div><br></div>