Usually I do strcpy but here is looking like I can’t copy bigger-sized to lower-sized array. I understand that I need to skip an array element for it, I want to skip first [0] element but how can I do it? I really don’t want to write something alike a[39]=b[40]; a[38]=b[39]... etc.
Usually I do strcpy but here is looking like I can’t copy bigger-sized to
Share
Play safe. Use
strncpyinstead ofstrcpy:It will work even if the last character in
bis not'\0', or there is'\0'somewhere at indexi.strncpyis particularly useful ifaandbare not to be treated as cstring, rather they’re just buffer which might or might not contain'\0'.In C++, you can also use
std::copyas:I usually prefer
std::copy, for it is generic and can be used with any iteratable type.