According to the book: How to C Programming - Eighth Edition (by Deitel brothers) this code reads the word "Hello":
#define SIZE 20
int main()
{
char MyStr[SIZE];
printf("Enter your word: ");
scanf("%19s", MyStr);
}
This picture is from the Sixth Edition online:
But when I do:
int main()
{
char MyStr[20];
printf("Enter your word: ");
scanf_s("%19s", MyStr);
}
I get Access Violation error:
What is that I am doing wrong?


scanf_s. It's a special function that requires special extra arguments in some cases.scanf_srequires the buffer size to be specified for all input parameters of type c, C, s, S, or [. The buffer size is passed as an additional parameter immediately following the pointer to the buffer or variable."scanf_sand lies aboutscanfnot being "safe" and whatnot - there is no change in safety here betweenscanfandscanf_sgiven the format from the book.scanf_s. It is found in Annex K of the standard, the "bounds checking interface".