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

  • Home
  • SEARCH
  • 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 7431309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:16:32+00:00 2026-05-29T09:16:32+00:00

I have programmed a self-made concat function: char * concat (char * str1, char

  • 0

I have programmed a self-made concat function:

char * concat (char * str1, char * str2) {
    for (int i=0; i<BUFSIZ; i++) {
        if (str1[i]=='\0') {
            for (int j=i; j<BUFSIZ; j++) {
                if (str2[j-i]=='\0') return str1;
                else str1[j]=str2[j-i];
            }
        }
    }
}

Now if I want to concat more than 2 strings, i.e. buf temp1 temp2,
I have to use something like that:

strcpy(buf, concat(concat(buf,temp1),temp2));

Please tell me, is there a simple way to modify my function so it would accept many arguments?

  • 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-29T09:16:33+00:00Added an answer on May 29, 2026 at 9:16 am

    The feature you’re looking for is varargs. This allows you to write a C function which accepts a variable number of arguments. It’s how functions like printf are implemented

    char* concat(size_t argCount, ...) {
      va_list ap;
    
      char* pFinal = ... // Allocate the buffer
      while (argCount) {
        char* pValue = va_arg(ap, char*);
        argCount--;
    
        // Concat pValue to pFinal
    
      }
      va_end(ap);
    
      return pFinal;
    }
    

    Now you can call concat with a variable number of arguments

    concat(2, "hello", " world");
    concat(4, "hel", "lo", " wo", "rld");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a mostly self-taught programmer, I have never really had anyone explain why certain
I am a self thought hobby programmer and therefore don't have the fundamentals always
I have programmed an emulator, but I have some doubts about how to organizate
Once I have programmed GUI with Java and have used Form Layouts. Form layout
I have been using oracle database throughout database courses, and I have programmed there
I have recently programmed a console application and I've experienced a lot of pain
I have never programmed a gadget for Vista or Seven, but I would like
I have a webservice programmed in coldfusion which I'm attempting to consume using c#.net.
I have multiple IPs on a NIC. I've programmed a console application to connect
I am a self-taught embedded developer. I mostly use AVRs programmed in C and

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.