Visual Studio C/C++ ucrtbased.dll Access Violation Writing Location


I'm using Visual Studio Enterprise 2015, I've been getting this error :

Exception thrown at 0x00007FF8E19979A3 (ucrtbased.dll) in Assignment 1C.exe: 0xC0000005: Access violation writing location 0x0000008836510000.

...whenever I use a char/string input, to the extent that this simple program:

#include <stdio.h>
#include <string.h>

int main() {
    char name[40], chk;

    printf("What is your name?");
    scanf_s("%s", name);
    chk = getchar();
    return 0;

is still giving me the same error. I don't know what is causing it though I suspect it's something from the libraries I'm using or the actual compiler? Open for suggestions.

asked on Stack Overflow Oct 29, 2015 by Logan • edited Oct 29, 2015 by too honest for this site

1 Answer


scanf_s() of argument is wrong.

scanf_s("%s", name, 40); or scanf_s("%s", name, _countof(name));

see also:

answered on Stack Overflow Nov 2, 2015 by Kenji Tokudome

User contributions licensed under CC BY-SA 3.0