#include <iostream>
#include <cstdarg>
#include <string.h>
using namespace std;
char* StrCat(char* des, char* src1, ...);
int main() {
char str[500] = "Fred";
StrCat(str, "Soly", "Moly", 0);
cout << str << endl;
return 0;
}
char* StrCat(char* des,char* src1, ...) {
strcat(des, src1);
va_list varg;
va_start(varg, src1);
char* i =va_arg(varg, char*);
while(i!=0) {
strcat(des, i);
i = va_arg(varg, char*);
}
va_end(varg);
return des;
}
output is :
FredSolyMoly
Its ironic to use strcat in a strcat function.
ReplyDeleteI took your version and made some adjustments:
http://peter.ug/strcat-function/