The strNcat Function Concatenates any Number of Strings Passed to It   Leave a comment

//
//  char* strNcat(char* dest, int num, …);
//
//  The strNcat function concatenates any number of strings passed to it.
//
//  Created by ED on 2013-02-02.
//

#include <cstdarg>
#include <cstdio>
#include <cstring>

char* strNcat(char* dest, int num, …) {
    va_list args;
    va_start(args, num);
    int i;
    for (i = 0; i < num; i++) {
        strcat(dest, va_arg (args, const char*));
    }
    va_end(args);
    return dest;
}

// int main() for testing only
int main() {
    char str[100];
    printf(“%s\n”, strNcat(str, 5, “Hello, “, “how “, “are “, “you “, “today?”));
    return 0;
}

Posted 2013/02/02 by oop344ed in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: