Why should you use strncpy instead of strcpy?

后端 未结 10 1049

Edit: I\'ve added the source for the example.

I came across this example:

char source[MAX] = \"123456789\";
char source1[MAX] = \"12         


        
10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 06:17

    That depends on our requirement. For windows users

    We use strncpy whenever we don't want to copy entire string or we want to copy only n number of characters. But strcpy copies the entire string including terminating null character.

    These links will help you more to know about strcpy and strncpy and where we can use.

    about strcpy

    about strncpy

提交回复
热议问题