08-23-2019 05:53 PM - edited 08-23-2019 05:53 PM
Hello all,
in the CVI help the documentation of the srtncpy you can read what's following
Output | ||
Name | Type | Description |
targetString | char [] | 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
08-24-2019 12:12 PM
Arrays are zero-based in C. If you want to copy n characters with strncpy you must:
The example in the documentation sounds good to me.