I've written this code in Visual Studio Community 2019 to copy string. It had no error when debug but came with error in stdio.h when compile, Here is the error:
Exception Thrown
Exception thrown at 0x00007FF890DEF455(ucrtbased.dll) in StringCopy.exe:0xC0000005:Access violation writing location 0x000000C45C100000
And here are the codes:
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
char s1[128],s2[128];
printf_s("Enter string:\n");
scanf_s("%s",s1);
for(i=0;s1[i]!='\0';i++)
{
s2[i] = s1[i];
}
s2[i] = '\0';
printf_s("The output string is : %s",s2);
return 0;
_getch();
}
If anyone can show me a full solution to this problem I'll be very grateful! Thank you!
User contributions licensed under CC BY-SA 3.0