Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Latest commit

 

History

History
46 lines (35 loc) · 1.14 KB

README.md

File metadata and controls

46 lines (35 loc) · 1.14 KB
layout title permalink
page
Q67790: %n Format Specifier May Be Ignored in C 6.00 sscanf()
/pubs/pc/reference/microsoft/kb/Q67790/

Q67790: %n Format Specifier May Be Ignored in C 6.00 sscanf()

Article: Q67790
Version(s): 6.00 6.00a | 6.00 6.00a
Operating System: MS-DOS     | OS/2
Flags: ENDUSER |
Last Modified: 6-FEB-1991

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 will be ignored and the sscanf()
function will return without making the %n assignment. This is correct
per ANSI specifications, since an input failure before the %n
parameter is evaluated.

The code below demonstrates the problem. Notice that the last
parameter passed (d) does not get 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
------

0  3  0