TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Frank Adam
from: David Nugent
date: 1996-01-14 23:44:32
subject: scanf()

DN>> The scanf() functions are difficult to use at best, and something
 DN>> probably  best avoided by a novice user (use fgets()). They are,

 FA> I certainly do avoid it :)
 FA> Is there any way of aborting input in scanf() ?
 FA> I mean detecting  on an empty line.
 FA> That was the primary reason why i stopped using it.

That depends entirely on what your parser string is, but yes, this is
indeed one of the problems.  You should understand that scanf() and family
is for *parsing data*, not providing a user interface. When the latter is
important (ie. when use interactively), then you need to be a bit more
clever at what is done, namely:

   if (fgets(buffer,buflen,fp)==NULL)
     abort ...
   if ((p=strchr(buffer,'\n'))  /* chop off newline */
     *p = '\0';
   if (sscanf(buffer,pattern,args...)==number_of_parse) {
     /* do your processing */
   }

And at this point, you're free to provide OTHER patterns on the same
string, which is something you don't get an opportunity to do with scanf(),
not to mention that the problem you mention does not exist.

--- MaltEd/2 1.0.b6
* Origin: Decadence BBS & Unique Computing - What a team! (3:632/348)
SEEN-BY: 50/99 620/243 623/630 632/103 348 360 998 633/371 634/384 388
SEEN-BY: 635/301 502 503 544 727 639/252 711/401 409 410 413 430 510 808 809
SEEN-BY: 711/932 934 712/515 713/888 714/906 800/1 7877/2809
@PATH: 632/348 635/503 50/99 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.