C - "Access violation writing location" when inputing string
Go to solution
Solved by Zalosath,
1 hour ago, Matttaj69 said:Hi,
I am working on a simple code in C, have got the logic almost sorted.
However, in order for my program to work, I need a user to input a string. I have tried <scanf_s("%s", potr);> (shown in picture), but while debugging, it has ended on that line with "Access violation writing location" error. I have tried putting the string directly as a parameter in the function call, which worked perfectly fine.
Any ideas what could be wrong?
Notice: long story short, I must use Microsoft Visual Studio and the "safe" version of scanf.
Screenshot of the part of my code:
Thanks in advance
You need to enter the length of the buffer for scanf_s.
scanf_s("%s", potr, sizeof(potr))
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now