📄 lib_scan.html
字号:
%u unsigned int *x strtoul 10 %hu unsigned short *x strtoul 10 %lu unsigned long *x strtoul 10 %x unsigned int *x strtoul 16 %hx unsigned short *x strtoul 16 %lx unsigned long *x strtoul 16 %X unsigned int *x strtoul 16 %hX unsigned short *x strtoul 16 %lX unsigned long *x strtoul 16 %[...] char x[]%l[...] wchar_t x[] %% <B>none</B></PRE><P>The scan conversion specifier (or<A HREF="#scan set">scan set</A>) determines any behaviornot summarized in this table. In the following descriptions,examples follow each of the scan conversion specifiers.In each example, the function<A HREF="stdio.html#sscanf"><CODE>sscanf</CODE></A>matches the <B><CODE>bold</CODE></B> characters.</P><P>You write <B><A NAME="%c"><CODE>%c</CODE></A></B>to store the matched input characters inan array object. If you specify no field width <I>w,</I> then <I>w</I>has the value one. The match does not skip leading<A HREF="lib_prin.html#white space">white space</A>. Anysequence of <I>w</I> characters matches the conversion pattern.</P><PRE>sscanf("<B>1</B>29E-2", "%c", &c) <B>stores '1'</B>sscanf("<B>12</B>9E-2", "%2c", &c[0]) <B>stores '1', '2'</B></PRE><P>For a<A HREF="lib_file.html#wide stream">wide stream</A>,conversion occurs as if by repeatedly calling<A HREF="wchar.html#wcrtomb"><CODE>wcrtomb</CODE></A>,beginning in the<A HREF="charset.html#initial conversion state">initial conversion state</A>.</P><PRE>swscanf(L"<B>1</B>29E-2", L"%c", &c) <B>stores '1'</B></PRE><P>You write <B><A NAME="%lc"><CODE>%lc</CODE></A></B>to store the matched input characters in an array object,with elements of type<A HREF="stddef.html#wchar_t">wchar_t</A>.If you specify no field width <I>w,</I> then <I>w</I>has the value one. The match does not skip leading<A HREF="lib_prin.html#white space">white space</A>. Anysequence of <I>w</I> characters matches the conversion pattern. For a<A HREF="lib_file.html#byte stream">byte stream</A>,conversion occurs as if by repeatedly calling<A HREF="wchar.html#wcrtomb"><CODE>mbrtowc</CODE></A>, beginning in the<A HREF="charset.html#initial conversion state">initial conversion state</A>.</P><PRE>sscanf("<B>1</B>29E-2", "%lc", &c) <B>stores L'1'</B>sscanf("<B>12</B>9E-2", "%2lc", &c) <B>stores L'1', L'2'</B>swscanf(L"<B>1</B>29E-2", L"%lc", &c) <B>stores L'1'</B></PRE><P>You write <B><A NAME="%d"><CODE>%d</CODE></A></B>,<B><A NAME="%i"><CODE>%i</CODE></A></B>,<B><A NAME="%o"><CODE>%o</CODE></A></B>,<B><A NAME="%u"><CODE>%u</CODE></A></B>,<B><A NAME="%x"><CODE>%x</CODE></A></B>, or<B><A NAME="%X"><CODE>%X</CODE></A></B> to convertthe matched input characters as a signed integerand store the result in an integer object.</P><PRE>sscanf("<B>129E</B>-2", "%o%d%x", &i, &j, &k) <B>stores 10, 9, 14</B></PRE><P>You write<B><A NAME="%e"><CODE>%e</CODE></A></B>,<B><A NAME="%E"><CODE>%E</CODE></A></B>,<B><A NAME="%f"><CODE>%f</CODE></A></B>,<B><A NAME="%g"><CODE>%g</CODE></A></B>, or<B><A NAME="%G"><CODE>%G</CODE></A></B>to convert the matched input characters as a signed fraction, withan optional exponent, and store the result in a floating-point object.</P><PRE>sscanf("<B>129E-2</B>", "%e", &f) <B>stores 1.29</B></PRE><P>You write <B><A NAME="%n"><CODE>%n</CODE></A></B>to store the number of charactersmatched (up to this point in the format) in an integer object. Thematch does not skip leading<A HREF="lib_prin.html#white space">white space</A>and does not match any input characters.</P><PRE>sscanf("<B>12</B>9E-2", "12%n", &i) <B>stores 2</B></PRE><P>You write <B><A NAME="%p"><CODE>%p</CODE></A></B>to convert the matched input characters asan external representation of a <I>pointer to void</I> and store theresult in an object of type <I>pointer to void.</I> The input charactersmust match the form generated by the<A HREF="lib_prin.html#%p"><CODE>%p</CODE></A><A HREF="lib_prin.html#print conversion specification">print conversion specification</A>.</P><PRE>sscanf("<B>129E</B>-2", "%p", &p) <B>stores, e.g. 0x129E</B></PRE><P>You write <B><A NAME="%s"><CODE>%s</CODE></A></B>to store the matched input characters inan array object, followed by a terminating null character. If youdo not specify a field width <I>w,</I> then <I>w</I> has a large value.Any sequence of up to <I>w</I> non white-space characters matchesthe conversion pattern.</P><PRE>sscanf("<B>129E-2</B>", "%s", &s[0]) <B>stores "129E-2"</B></PRE><P>For a<A HREF="lib_file.html#wide stream">wide stream</A>,conversion occurs as if by repeatedly calling<CODE>wcrtomb</CODE> beginning in the<A HREF="charset.html#initial conversion state">initial conversion state</A>.</P><PRE>swscanf(L"<B>129E-2</B>", L"%s", &s[0]) <B>stores "129E-2"</B></PRE><P>You write <B><A NAME="%ls"><CODE>%ls</CODE></A></B>to store the matched input characters inan array object, with elements of type<A HREF="stddef.html#wchar_t">wchar_t</A>,followed by a terminating null wide character. If youdo not specify a field width <I>w,</I> then <I>w</I> has a large value.Any sequence of up to <I>w</I> non white-space characters matchesthe conversion pattern. For a<A HREF="lib_file.html#byte stream">byte stream</A>,conversion occurs as if by repeatedly calling<A HREF="wchar.html#mbrtowc"><CODE>mbrtowc</CODE></A>,beginning in the<A HREF="charset.html#initial conversion state">initial conversion state</A>.</P><PRE>sscanf("<B>129E-2</B>", "%ls", &s[0]) <B>stores L"129E-2"</B>swscanf(L"<B>129E-2</B>", L"%ls", &s[0]) <B>stores L"129E-2"</B></PRE><P>You write <B><A NAME="%["><CODE>%[</CODE></A></B>to store the matched input characters inan array object, followed by a terminating null character. If youdo not specify a field width <I>w,</I> then <I>w</I> has a large value.The match does not skip leading<A HREF="lib_prin.html#white space">white space</A>.A sequence of up to <I>w</I>characters matches the conversion pattern in the<B><A NAME="scan set">scan set</A></B> that follows.To complete the scan set, you follow the left bracket(<CODE>[</CODE>) in the conversion specification with a sequenceof zero or more <B>match</B> characters, terminated by a right bracket(<B><CODE>]</CODE></B>).</P><P>If you do not write a caret (<B><CODE>^</CODE></B>)immediately after the <CODE>[</CODE>, then eachinput character must match <I>one</I> of the matchcharacters. Otherwise, each input character must not match <I>any</I>of the match characters, which begin with the character followingthe <CODE>^</CODE>. If you write a <B><CODE>]</CODE></B>immediately after the <CODE>[</CODE> or <CODE>[^</CODE>,then the <CODE>]</CODE> is the first match character, notthe terminating <CODE>]</CODE>. If you write a minus(<B><CODE>-</CODE></B>) as other than the first or last match character,an implementation can give it special meaning.It usually indicates a range of characters, in conjunction with thecharacters immediately preceding or following, as in<CODE>0-9</CODE> for all the digits.)You cannot specify a null match character.</P><PRE>sscanf("<B>12</B>9E-2", "%[54321]", &s[0]) <B>stores "12"</B></PRE><P> For a <A HREF="lib_file.html#wide stream">wide stream</A>,conversion occurs as if by repeatedly calling<A HREF="wchar.html#wcrtomb"><CODE>wcrtomb</CODE></A>,beginning in the<A HREF="charset.html#initial conversion state">initial conversion state</A>.</P><PRE>swscanf(L"<B>12</B>9E-2", L"%[54321]", &s[0]) <B>stores "12"</B></PRE><P>You write <B><A NAME="%l["><CODE>%l[</CODE></A></B>to store the matched input characters inan array object, with elements of type<A HREF="stddef.html#wchar_t">wchar_t</A>,followed by a terminating null wide character. If youdo not specify a field width <I>w,</I> then <I>w</I> has a large value.The match does not skip leading<A HREF="lib_prin.html#white space">white space</A>.A sequence of up to <I>w</I>characters matches the conversion pattern in the<A HREF="#scan set">scan set</A> that follows.<P> For a <A HREF="lib_file.html#byte stream">byte stream</A>,conversion occurs as if by repeatedly calling<A HREF="wchar.html#mbrtowc"><CODE>mbrtowc</CODE></A>,beginning in the<A HREF="charset.html#initial conversion state">initial conversion state</A>.</P><PRE>sscanf("<B>12</B>9E-2", "%l[54321]", &s[0]) <B>stores L"12"</B>swscanf(L"<B>12</B>9E-2", L"%l[54321]", &s[0]) <B>stores L"12"</B></PRE><P>You write <B><A NAME="%%"><CODE>%%</CODE></A></B>to match the percent character (<CODE>%</CODE>).The function does not store a value.</P><PRE>sscanf("<B>% 0XA</B>", "%% %i", &i) <B>stores 10</B></PRE><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pb.html">Copyright</A> © 1989-2002by P.J. Plauger and Jim Brodie. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -