The main difference between the more secure functions (that have the _s suffix) and the other versions is that the more secure functions require the size in characters of each c, C, s, S, and [ type field to be passed as an argument immediately following the variable. For more information, see scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l and scanf Width Specification.
The versions of these functions that have the _l suffix are identical except that they use the locale parameter thats passed in instead of the current thread locale.
Generic-Text Routine Mappings
TCHAR.H routine
_UNICODE & _MBCS not defined

_MBCS defined
_UNICODE defined
Function
Required header
For additional compatibility information, see Compatibility.
// crt_fscanf_s.c
// This program writes formatted
// data to a file. It then uses fscanf to
// read the various data back from the file.
#include <stdio.h>
#include <stdlib.h>
FILE *stream;
int main( void )
{
long l;
float fp;
char s[81];
char c;
errno_t err = fopen_s( &stream, "fscanf.out", "w+" );
if( err )
printf_s( "The file fscanf.out was not opened\n" );
else
{
fprintf_s( stream, "%s %ld %f%c", "a-string",
65000, 3.14159, x );
// Set pointer to beginning of file:
fseek( stream, 0L, SEEK_SET );
// Read data back from file:
fscanf_s( stream, "%s", s, _countof(s) );
fscanf_s( stream, "%ld", &l );
fscanf_s( stream, "%f", &fp );
fscanf_s( stream, "%c", &c, 1 );
// Output data read:
printf( "%s\n", s );
printf( "%ld\n", l );
printf( "%f\n", fp );
printf( "%c\n", c );
fclose( stream );
}
}
a-string 65000 3.141590 x

System::IO::StreamReader::ReadLine. See also Parse methods, such as System::Double::Parse.
Stream I/O
_cscanf_s, _cscanf_s_l, _cwscanf_s, _cwscanf_s_l
fprintf_s, _fprintf_s_l, fwprintf_s, _fwprintf_s_l
scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l
根本感觉不到sscanf 与 sscanf_s 的区别。 sscanf_s( tokenstring, "%s", s, _countof(s) )。下面总结了sscanf的以及sscanf_s的常用方法,也体现了“_s”版本函数与原函数的特别之处:。
fscanf, _fscanf_l, fwscanf, _fwscanf_l
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-94874-2.html
干嘛不和叙利亚比啊
美国有点气急败坏
好好读一读刘亚洲的文章就知道了