#include <stdio.h>
int main(){
char s[10];
scanf_s("%s", s);
for (int i = 0; i < 10; i++)
printf("%s\n", s);
}
This error appears in visual studio
Exception thrown at 0x7B8BEF1C (ucrtbased.dll) in 1.exe: 0xC0000005: Access violation writing location 0x00942000.enter image description here
You're missing arguments. The proper usage is
scanf_s("%s", s, 10);
or
scanf_s("%9s", s, 10);
(These are slightly different.)
You should also check the value returned before using s
.
User contributions licensed under CC BY-SA 3.0