ID Number: Q67790
6.00 6.00a 6.00ax | 6.00 6.00a
MS-DOS | OS/2
Summary:
In Microsoft C versions 6.0, 6.0a, and 6.0ax, if the "%n" format
specifier is used within a sscanf() function and the format specifier
before it causes the last character to be read from the string of
data, the %n is ignored and the sscanf() function returns without
making the %n assignment. This is correct per ANSI specifications,
because an input failure occurs before the %n parameter is evaluated.
The code below demonstrates the problem. Notice that the last
parameter passed (d) is not changed. The sscanf() statement finishes
making assignments as soon as it reaches the end of the string.
Sample Code
-----------
#include <stdio.h>
void main(void)
{
int a,b,c,d;
char buffer[50];
a=b=c=d=0;
sscanf("100Dummy2","%n%d%n%s%n",&a,&b,&c,buffer,&d);
printf("%d %d %d\n",a,c,d);
}
Output for C 6.0, 6.0a, and 6.0ax
---------------------------------
0 3 0
Output for C/C++ 7.0
--------------------
0 3 9
Additional reference words: 6.00 6.00a 6.00ax