On Wed, 10 Sep 1997, Rich Chiavaroli wrote: -+Well, just from what I've learned (the hard way I might add) if you -+add the 4th "%d" on the the last line of values, you have to make sure -+that (only if you're using Oasis I guess) you write out all 0's to that -+field first. Err, go back and read the message (and especially the pseudo-code) again. sscanf() does not require you to meet the format exactly and returns how many things it could match to the given format. For instance, try: int i, j, k, l; i = j = k = l = 0; printf("%d: %d, %d, %d, %d", sscanf("2 5 6", "%d %d %d %d", &i, &j, &k, &l), i, j, k, l); This will print: 3: 2 5 6 0 Note that we have passed "2 5 6", which does not have four arguments as the format "requires". This is because it doesn't really require the string to match the format, it just matches the string to the format as best as it can. In CircleMUD we get the restriction because it tests how many variables matched the format and reports an error if it doesn't meet the format "requirement". In other words, Circle does something along the lines of: if (sscanf("2 5 6", "%d %d %d", &i, &j, &k) != 3) printf("error\n"); My suggestion was adding a fourth optional argument by making the != 3 "< 3". In other words, the error is only reported if sscanf() gets less than 3 arguments. Otherwise it accepts 3 or 4 arguments (it won't get five, because that goes beyond the format). So, my change was: if (sscanf("2 5 6", "%d %d %d %d", &i, &j, &k, &l) < 3) printf("error\n"); See? We can get up to four arguments, but if we only get 3, we don't report a problem. We just let l alone unless we have enough arguments in the first string ("2 5 6"). An actual implemetation of this would lie along the lines of: if ((count = sscanf(line, " %d %d %d %d ", t, t+1, t+2, t+3)) < 3) { report the error; } obj.value[0] = t[0]; obj.value[1] = t[1]; obj.value[2] = t[2]; /* required variables */ obj.value[3] = (count > 3 ? t[3] : 0); /* optional */ Understand? [or did I misunderstand what you were saying] -- Daniel Koepke -:- dkoepke@california.com -:- [Shadowlord/Nether] Think. +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST