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
This is a discussion on Quick question on pointers within the C Programming forums, part of the General Programming Boards category; If i have the a pointer called buf1 and it contains aload of data, is it ok to do the ...
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.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way