Could anyone be kind enough to help me figure out why my code doesn't work? It's my first time trying anything with variadic functions, but from the few tutorials I've seen this should run. I'm using codeblocks and it doesn't produce any errors, but the program crashes when it gets to:
p = va_arg(ap, char);
here's the full function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
string string_replace(string &s, char r, int countc, ...){
char p;
va_list ap;
va_start (ap, countc);
for (int j = 0; j < countc; j++){
p = va_arg(ap, char);
for (int i = 0; i < s.length(); i++){
if (s[i] == p){
s[i] = r;
}
}
}
va_end(ap);
return s;
}