If you just set the first char in the string to 0, you also have to remember to null terminate the string when you set the other chars (as Galik said above)
Andy
P.S. Yet another way to zero an array variable!
memset(lTemp, 0, sizeof(lTemp);
With an array allocated with new you should use
char *pTemp = new char[1024]();
The trailing () tells the compiler to zero all the elements.
To re-zero the whole array, use memset, but with the array size (here, 1024) and not sizeof(pTemp) !
P.P.S. To initialize an array to zero (all element), you can use any of
1 2 3
|
char a1[16] = "";
char a2[16] = {0};
char a3[16] = {'\0'};
|
The rule for aggregate init is that if you init any but not all members/elements, the rest are zeroed. If you init none, it is just left alone. So zeroing the first elem is enough to zero all elems.
With VC, empty braces also works (= {};). But I don't know if that is standard behaviour.
(Out of habit I use the first form if the buffer is to contain a null terminated string; the second if it's to be treated as individual chars. )