Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question: EOF on Standard Input : ???

Status
Not open for further replies.

AnnaHere

IS-IT--Management
May 16, 2000
17
0
0
AU
<br>Hi all,<br>Anbybody that can help, if I am reading input from STDIN, how is an EOF determined.<br>And can I resume to the next program line after an EOF is reached.<br><br>&nbsp;&nbsp;..<br>&nbsp;&nbsp;..<br>&nbsp;&nbsp;while ((ch = fgetc (stdin)) != EOF)<br>&nbsp;&nbsp;&nbsp;&nbsp;fputc(ch,stdout);<br>&nbsp;&nbsp;printf(&quot;Hello&quot;);<br>&nbsp;&nbsp;..<br>&nbsp;&nbsp;..<br>&nbsp;&nbsp;<br>Anna
 
Hi Anna,<br>&nbsp;&nbsp;I have a question, I dunno which platform you are working. If it is unix, you can use, ctrl D for specifying EOF and the above code will work perfectly.<br>&nbsp;&nbsp;If it is in windows platform. i think i need to check and come back to you.<br><br>Regards,<br>Baskar.
 
Hi anna,<br>&nbsp;&nbsp;In Windows environment, you can use char 255, i.e press alt and press 255 then leave alt key , press enter, this means that u have entered EOF in stdin. BTW make sure that NUM lock is turned off.<br><br>&nbsp;&nbsp;Hope this helps you.<br><br>Regards,<br>Baskar. <p>Baskar<br><a href=mailto:baskar52@hotmail.com>baskar52@hotmail.com</a><br><a href= to Basking's Home page</a><br>
 
ctrl-D or alt+225 are a bit obscure and presuming that someone else will be using the program they may not know to use these characters instead it may be useful to have your own special character to signify the end of the users input. for example a simple tally program:<br><br>printf(&quot;Enter numbers (0-9) of q to quit\n);<br>while((ch = fgetc(stdin))!='q'){<br>total=total+atoi(&ch); <br>}<br>printf(&quot;Total is %d\n&quot;, total);<br><br>this works only for numbers between 0 and 9 because we're using getc instead of gets or scanf it could be changed to take strings but then checking for eof or a special character will change it to <br>while(true){<br>str=fgets(stdin);<br>if(str[0]=='q'){/* or EOF*/<br>break;<br>}<br>/*do stuff here*/<br>}
 
Ctrl-D/Z will work like EOF . Just try it.<br><br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A> <p>Siddhartha Singh<br><a href=mailto:siddhu_singh@hotmail.com>siddhu_singh@hotmail.com</a><br><a href=siddhu.freehosting.net> </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top