strcat Vs strncat - When should which function be used?

后端 未结 5 873
无人及你
无人及你 2021-01-02 11:55

Some static code analyzer tools are suggesting that all strcat usage should be replaced with strncat for safety purpose?

In a program, if we know clearly the size of

5条回答
  •  情话喂你
    2021-01-02 12:11

    It's very simple strcat is used to concatenate two strings , for example

    String a= data 
    String b = structures 
    

    If use perform strcat

    Strcat(a, b) 
    

    then

    a= data structures
    

    But if you want to concatenate specific numer of word r elements then you can use strncat Example if you want to concatenate only the first two alphabet lts of b into a then you have to write Strncat(a,b,2) (It means that you just cancatenate the fist two alphabets of b into a , and a becomes a = data st

提交回复
热议问题