Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:20:39+00:00 2026-05-27T08:20:39+00:00

i have this function char* copy(char* pString,…){ char *vToate; int vLen; va_list vAp; va_start(vAp,pString);

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:20:40+00:00Added an answer on May 27, 2026 at 8:20 am

    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:

    char *copy(char *str, ...)
    {
        va_arg ap;
        va_start(str, ap);
        int len = 0;
        char *sp;
        for(sp=str; sp; sp=va_arg(ap, char*))
            len+=strlen(sp);
        va_end(ap);
        va_start(ap);
        char *dst = new char[len+1];
        int pos = 0;        
        for(sp=str; sp; sp=va_arg(ap, char*)){
            memcpy(dst+pos, sp, strlen(sp));
            pos+=strlen(sp);
        }
        va_end(ap);
        dst[pos] = '\0';
        return dst;
    }
    

    Which you would then call:

    char *str = copy("foo", " ", "bar", NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function: void ToUpper(char * S) { while (*S!=0) { *S=(*S >=
I have a function using strtok like this void f1(char *name) { ... char
I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if
I have this function signature I have to match typedef int (*lua_CFunction) (lua_State *L);//target
I have this look up table : char *table[ascii][morse]; where ascii is an int
I would like to try C memcpy function. I have this code: char destination[40];
In a C dll, I have a function like this: char* GetSomeText(char* szInputText) {
I have problem running and debugging this piece of code: bool readSectionHeaders(char* path, int
I have this function in my Javascript Code that updates html fields with their
I have this function in my head: <head> window.onload = function(){ var x =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.