Thread View: net.bugs
1 messages
1 total messages
Started by Geoff Collyer
Fri, 07 Sep 1984 01:35
scanf returns short count on null field(s)
Author: Geoff Collyer
Date: Fri, 07 Sep 1984 01:35
Date: Fri, 07 Sep 1984 01:35
41 lines
1426 bytes
1426 bytes
At least under format %[, the count scanf returns is too low by the
number of null fields read. This bug appears in the v7 and 4.2bsd stdio
implementations, so it is likely in all AT&T scanfs, though I haven't checked.
I have added this to the BUGS section of scanf(3S):
---
.PP
The
.I scanf
functions return a count which is too low by the number
of null fields scanned.
---
The follow program demonstrates the bug:
---
#include <stdio.h>
main()
{
char line[200];
char s1[200], s2[200], s3[200], s4[200], s5[200];
while (fgets(line, sizeof line, stdin) != NULL) {
s1[0] = s2[0] = s3[0] = s4[0] = s5[0] = 0;
printf("sscanf returned %d\n",
sscanf(line,
"%[^:\n]:%[^:\n]:%[^:\n]:%[^:\n]:%[^:\n]\n",
s1, s2, s3, s4, s5));
printf("tokens: `%s' `%s' `%s' `%s' `%s'\n",
s1, s2, s3, s4, s5);
}
exit(0);
}
---
Try the following input:
---
a:b:c:d:e
:b:c:d:e
::c:d:e
:::d:e
---
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads