I have a character pointer which points to the character array. I want to clear the character array and then string copy some other array in it.The memset doesn't work on char pointer. Is there some other way around to do that ?
int main(){
char a[100] = "coepismycollege";
char *p;
p = a;
test(p);
printf("After function : %s", a);
}
void test(char *text){
char res[120] = "stackisjustgreat";
printf("text = %s\nres = %s\n", text , res);
memset(&text, 0 , sizeof(*text));
strcpy(text, res);
}
output should be : stackisjustgreat
Thanks in advance.
memset(&text, 0 , sizeof(*text));-->memset(text, 0 , strlen(text));But in this casememsetis not necessary.-Wallon gcc or clang.