why can't I do :
strncpy (str2,NULL,5);
This is a discussion on strncpy problem within the C Programming forums, part of the General Programming Boards category; why can't I do : strncpy (str2,NULL,5);...
why can't I do :
strncpy (str2,NULL,5);
Why? Because NULL is not a string.
Where is strncpy supposed to read the data (the source) to copy into the destination?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
so what do I do to assign str2 to NULL?
If str2 is an array:
If str2 is a pointer:Code:str2[0] = '\0';
Code:str2 = NULL;
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
or if the string contains something sensitive like passwords, and you want to be extra secure, you can wipe the whole string like this:
Of course sizeof will only work if str2 is an array; if it's a pointer you need to know the actual size...Code:memset( str2, '\0', sizeof( str2 ) );
In most cases though, I'd just set the first character to NUL like Elysia showed.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010