> > This will print: > > 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"); This is what I did... > > 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 */ > I didn't make the the assignment conditional...which was my problem. If you don't either do that or assign all the vars to 0 (or at least l) before reading the last line, it will use the value that scanf() read into l from the line that did have 4 values. I wasn't or didn't get any errors from only reading in 3 values when it could read up to 4. It was the assignment that caused the problem when there l was never reinitialized to 0 and no value was read over the top of it (actually t[3]). Make more sense? Wasn't trying to say that your method was wrong, just that if someone was going to do this, they need to make sure that they take care of this condition by writing out all 0's first. Thats how I handled it. Or use your conditional assignment. -Rich +------------------------------------------------------------+ | 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