Language/C, C++
[ C ] scanf / scanf_s 차이점
땅굴파는 초보개발자
2021. 1. 7. 23:35
1. scanf_s 란?
This function is specific to Microsoft compilers. It is the same as scanf, except it does not cause buffer overload. It takes the input in a text based console program and places it into a variable.
: 즉, scanf와 같이 입력을 받는 기능은 동일하지만, scanf에서 문제가 되었던, 버퍼 오버플로우를 방지할 수 있다.
[↓ 비주얼 스튜디오에서 'scanf' 함수를 사용했을 때, 나타나는 에러]
'scanf': This function or variable may be unsafe.
Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
See online help for details.
ex) scanf_s(서식지정자, (&)변수, sizeof(변수));
2. 추가 사항
(1) scanf("%[^\n]s", input)
: 공백을 포함한 문자열을 입력 받을 때 해당 서식지정자(%[^\n]s)를 사용한다.