i have this function
char* copy(char* pString,...){
char *vToate;
int vLen;
va_list vAp;
va_start(vAp,pString);
vLen+=strlen(pString);
va_end(vAp);
vToate=new char[vLen+1];
va_list vAp1;
va_start(vAp1,pString);
strncpy(vToate,pString,strlen(pString));
va_end(vAp1);
return vToate;
}
if i try this
char *vTest="test";
char *vTmp=copy(vTest," ",vTest);
cout<<vTmp;
the result are “test” not “test test”
what are wrong ?
It looks you’re unclear about how to use variadic macros. You forgot to call va_arg to get each next element. You also need a length or sentinel value, so you can know when there aren’t any more arguments. It seems like you want this:
Which you would then call: