c언어 여러 문자 scanf_s 입력
조회수 1445회
문자열로 입력을 안하고 문자, 문자로 입력하고 합니다. 근데
char a;
scanf_s("%c", &a);
printf("%c", a);
이렇게 하면 에러가 안나는데
char a, b;
scanf_s("%c%c", &a, &b);
printf("%c%c", a, b);
이렇게 하면 에러가 납니다. 어느 부분이 잘못된 건가요???
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
1 답변
-
여기서,
Unlike scanf and wscanf, scanf_s and wscanf_s require you to specify buffer sizes for some parameters. Specify the sizes for all c, C, s, S
scanf_s, wscanf_s 는 (scanf, wscanf 와는 다르게) c, C, s, S 등에 대해서는 버퍼크기를 지정해주어야 한다.
아래 예제를 보면, c 에도 1이라고 크기를 지정하고 있는 걸 알 수 있어요.
result = scanf_s( "%d %f %c %C %s %S", &i, &fp, &c, 1, &wc, 1, s, (unsigned)_countof(s), ws, (unsigned)_countof(ws) );
댓글 입력