strcat Vs strncat - When should which function be used?

Viewed 31834

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 the target buffer and source buffers, is it still recommended to go for strncat?

Also, given the suggestions by static tools, should strcat be used ever?

5 Answers

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

Related