If i have the a pointer called buf1 and it contains aload of data, is it ok to do the following:
Code:char *buf2 memset(buf2, '/0' 70); strncpy(buf2, buf1, 70);
I know you use memset with arrays but is it ok to do it with a pointer?
Thanks
If i have the a pointer called buf1 and it contains aload of data, is it ok to do the following:
Code:char *buf2 memset(buf2, '/0' 70); strncpy(buf2, buf1, 70);
I know you use memset with arrays but is it ok to do it with a pointer?
Thanks
Assuming that buf2 has enough space for 70 chars, yes. But you should use '\0' and not '/0'.
cheers always get those slashes wrong!
buf2 will have enough space.
Ah, but of course that is colloquial speech. It is not buf2 that will have enough space, but the (dynamic) array whose first element buf2 points to that should have enough space.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)