Reputation: 277
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.
Upvotes: 1
Views: 13004
Reputation: 125
scanf_s() of argument is wrong.
scanf_s("%s", name, 40); or scanf_s("%s", name, _countof(name));
see also: https://msdn.microsoft.com/en-us/library/w40768et.aspx
Upvotes: 1