c - Differences between scanf & scanf_s -
this question has answer here:
- difference between scanf , scanf_s 4 answers
what's difference between scanf
, scanf_s
in c. i'm using visual studio 13 , keeps on giving me errors when try use scanf
.
both read formatted data standard input stream. '_s
' microsoft's 'secure' versions.
these versions of scanf, _scanf_l, wscanf, _wscanf_l have security enhancements, described in security features in crt:
many old crt functions have newer, more secure versions. if secure function exists, older, less secure version marked deprecated , new version has _s ("secure") suffix.
in context, "deprecated" means function's use not recommended; not indicate function scheduled removed crt.
the secure functions not prevent or correct security errors; rather, catch errors when occur. perform additional checks error conditions, , in case of error, invoke error handler (see parameter validation).
for example, strcpy function has no way of telling if string copying big destination buffer. however, secure counterpart, strcpy_s, takes size of buffer parameter, can determine if buffer overrun occur. if use strcpy_s copy eleven characters ten-character buffer, error on part; strcpy_s cannot correct mistake, can detect error , inform invoking invalid parameter handler.
Comments
Post a Comment