I was just messing around with C and ran into this small problem. As you can see from my output I getting '╠' this character.
#include <stdio.h>
int main(void)
{
char c;
printf("Do you want to be X's or O's?\n");
scanf_s("%c", &c);
printf("You chose %c\n", c);
}
See program output
You are misusing
scanf_s()
. Microsoft compilers may warn you to use their secure extensions (aka c11 annex k). But, be careful if you do so.scanf_s()
is not a direct replacement forscanf()
.In this case you have to pass the size of the output buffer as an extra argument.
Having to put a 1 as the size of a single character may seem a bit pedantic. That's because
%c
can read any number of character.%c
is just an alias for%1c
(a single character).By knowing the buffer size
scanf_s()
is designed to prevent buffer overflow (a security risk).Although, how much these functions really help is debatable. See: Field Experience With Annex K.
According to msdn: