#include <iostream>
#include <stdarg.h>
const char* nstrcat(char* des,...);
void merge(char*, char*);
const char* nstrcat(char* des,...){
va_list pass;
va_start(pass,des);
char* base;
while(base=va_arg(pass,char*)){
if(base)merge(des,base);
else break;
}
va_end(pass);
return des;
}
void merge(char* des,char* base){
int i=0,j=0;
for(i;des[i];i++);
for(i;base[j];i++,j++){
des[i]=base[j];
}
}
The hardest thing to wrap your head around when you first start working with va_list's (it seems to me) is the idea that each time you reference the list with va_arg it advances the the address pointer for the parameter list. Once you figure out how to work with that the rest goes pretty easy.
No comments:
Post a Comment