I am a newbie to C still, and I am having a problem with the memset function.
I pass a char * to a function, and inside this function I create an array, and then use memset to set each value. I have been using dbx to watch this variable as it enters the function, and for some reason it gets set to "" after we pass memset.
Firstly, why does this happen? I'm assuming that memset must be resetting the memory where the char * is located?
Secondly, is there a better way to set each element as "0"?
Here is my code:
static char *writeMyStr(char *myStr, int wCount) {
// here myStr is set to "My String is populated"
char **myArr;
myArr = (char **) malloc(sizeof(char *) * wCount);
memset(myArr, 0, sizeof(char *) * wCount); // myStr is set to ""
... populate array ...
}
malloc
, because you have to interact with C code, for example. – rodrigo