Here's the problem i just met. Every time i try to copy str1 to str3 using strcpy command Visual Studio 2015 gives me a warning message and saying that strcpy and strrev is unsafe and suggest me to use strcpy_s and strrev_s instead. Can anyone explain why strcpy and strrev is unsafe ?and what are the safer alternatives of strcpy and strrev. Here is my code:

   int main(){
    char str1[10] = "Hello", str2[10] = "World", str3[10];
    strcpy(str3, str1);//here showing an error
    strrev(str1);//here also showing an error
    cout << str3 << "  " << str1 << endl;
    return 0;

asked 07 Mar '16, 20:30

Zahirul_Islam_Monir's gravatar image


edited 08 Mar '16, 11:18

so, in title, where did strcat come from?

(08 Mar '16, 03:57) manetsus

As you have asked it in English, I will answer it in English.

To be brief, strcpy doesn't have a parameter of the length of the string. So it cannot understand the size of the string and some problems occur, such as wrong output, sudden crash etc.

As far as I know, strrev also has the same problem, not sure though. Besides strrev is not allowed in programming contests and heard that it doesn't work with Linax.

Oh by the way,you can use strncpy. Have a look here:

All your problems have another solution though. If you work with C++, use STL string. It will solve all your problems. :)

Have a look here:

Hope it helps. :)

permanent link

answered 09 Mar '16, 10:57

R_Abid's gravatar image


edited 09 Mar '16, 11:01

ধন্যবান ভাইয়া

(09 Mar '16, 13:05) Zahirul_Islam_Monir
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 07 Mar '16, 20:30

question was seen: 1,287 times

last updated: 09 Mar '16, 13:05