Author: Dieter Buerssner
Date: 09:06:16 11/22/04
Go up one level in this thread
Uri, I cannot fully understand. First of all, using a global buffer seems wrong, or at least fragile, when the function you use the buffer in can be interrupted by another function that uses the same buffer. Then I don't understand why you use scanf for reading PGN? scanf reads from stdin, not from a disk file. Did you mean sscanf of fscanf? (I see that you expicetly mentioned scanf and sscanf in your post). sscanf certainly should not touch stdin->_cnt. Using the scanf family correctly is not easy (perhaps with the exception of sscanf). Error recovery is tricky, perhaps impossible in some cases. If intput is always guaranteed to be correct it is a different matter. From comp.lang.c FAQ: <<< Question 12.20 Why does everyone say not to use scanf? What should I use instead? -------------------------------------------------------------------------------- scanf has a number of problems--see questions 12.17, 12.18, and 12.19. Also, its %s format has the same problem that gets() has (see question 12.23)--it's hard to guarantee that the receiving buffer won't overflow. More generally, scanf is designed for relatively structured, formatted input (its name is in fact derived from ``scan formatted''). If you pay attention, it will tell you whether it succeeded or failed, but it can tell you only approximately where it failed, and not at all how or why. It's nearly impossible to do decent error recovery with scanf; usually it's far easier to read entire lines (with fgets or the like), then interpret them, either using sscanf or some other techniques. (Routines like strtol, strtok, and atoi are often useful; see also question 13.6.) If you do use sscanf, don't forget to check the return value to make sure that the expected number of items were found. References: K&R2 Sec. 7.4 p. 159 >>> Regards, Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.