hello gurus,
I have the following code:
char em[_POSIX_PATH_MAX];
memset(em, 0, _POSIX_PATH_MAX);
snprintf(em, sizeof(em), "%s/db/abc", root_ptr);
is memset needed here, or will snprintf work without any errors?
thanks
hello gurus,
I have the following code:
char em[_POSIX_PATH_MAX];
memset(em, 0, _POSIX_PATH_MAX);
snprintf(em, sizeof(em), "%s/db/abc", root_ptr);
is memset needed here, or will snprintf work without any errors?
thanks
memset() is not needed. snprintf() will terminate the string with a null.Originally posted by webwesen
is memset needed here, or will snprintf work without any errors?
Jason Deckard
thanks Jason!
your help is appreciated
Additionally, you could just initialize your array in one shot at creation time.Originally posted by Deckard
memset() is not needed. snprintf() will terminate the string with a null.
There are two ways to zero value an array. One will give you different end results, but initially, it will be zeroed:
a) the better way:
char em[SOMESIZE] = {0};
b) the odd way:
static char em[SOMESIZE];
Now the second (b) will behave in a rather different way than you exepct, however, it would actually initialize the array to zero value the first time the function was called. (After that, it'd have whatever value you had left in it the time before.)
Obviously the first is the way to go, but I thought I would throw the other out, becuse it does zero value it.
Quzah.
Hope is the first step on the road to disappointment.