Home > Back-end >  Ask a c primer plus
Ask a c primer plus

Time:04-21

Book code line 10 no. 4 (figure 3), but if you don't add 4 would be a mistake (as shown in figure 2) can only be run normally, with 4 + 1, but added after 5555 had the (figure 5), who can explain well the

CodePudding user response:

With scanf_s the scanf () () there is a difference between, line 10 right should be: scanf_s (" % s ", name, 40).
https://blog.csdn.net/weixin_44093867/article/details/97525914? Ops_request_misc=% 257 b % 2522 request 255 fid 253 a % 2522161889596316780269825965% % 2522% % 2522% % 252 c 2522 SCM 253 a % % 2522% 252220140713.130102334.. % 2522% 257 d & amp; Request_id=161889596316780269825965 & amp; Biz_id=0 & amp; Utm_medium=distribute. Pc_search_result. None - task - blog - 2 ~ ~ top_click ~ all default - 1-97525914. Pc_search_result_no_baidu_js & amp; Utm_term=E7 8 escanf B8 E4 scanf_s % % % % % a % % 84% E5 8 of 9 E5 BA c % % % 88% AB

CodePudding user response:

The book is the scanf and your compiler requirement is scanf_s, encapsulation, was conducted again just for the scanf safer than the scanf, because it limits the buffer length, can effectively prevent cross-border;
More of the parameters cannot be introduced into 4, and need to 40;

CodePudding user response:

Man scanf_s
Oh, no manual Windows, jump to scanf_s interface directly see the specification parameters

CodePudding user response:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l? View=MSVC - 160
  • Related