Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5357

Dubt on strncpy documentation

$
0
0

Hello all, 

 

in the CVI help the documentation of the srtncpy you can read what's following

 

Output
NameTypeDescription
targetStringchar []Contains the target string to which the specified number of characters from the source string are copied. If the source string is shorter than maxChars, ASCII NUL bytes are appended to the contents of this parameter until maxChars are written. If the source string is longer than maxChars, no ASCII NUL bytes are written to the contents of this parameter. If you want to guarantee that an ASCII NUL byte is at the end of the copied bytes, you can use the following:

strncpy (target, source, n);
target[n] = 0;

 

I've put in bold + underline the relevant part.

I've a doubt about the code snippet provided as example

How could it be? I mean, it sounds like an off-by-one to me

 

May I have your kind opinion?

 

Tanks in advance

All the best


Viewing all articles
Browse latest Browse all 5357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>