Help with a function that accepts different parameter types I'm trying to create a function that prints out an XML tag with a value. I have the code below, but kind of stuck. I'd like to be able to call the function, and pass a value that could be a float, int, string or char. Appreciate any help.

char PingTime[6] = "3ms";
char PingText[60] = "ping reply blah blah";
float humidity = "40.56";
int DigialPin = 0;

PrintXMLTag(cl,"pingtime",PingTime); 
PrintXMLTag(cl,"PingText",PingText);  
PrintXMLTag(cl,"humidity",humidity);    
PrintXMLTag(cl,"DigialPin",DigialPin);  

void PrintXMLTag_DEC(EthernetClient cl, const char* tag, NotSure?? val) 
{
  char tmp [100];
  StrClear(tmp,100);

  // If val type is float ----------------------
  int d1 = val; // Get the integer part 
  float f2 = val - d1; // Get fractional part 
  int d2 = trunc(f2 * 10000);// Turn into integer 
  sprintf(tmp,"&lt;%s&gt;%d.%02d&lt;/%s&gt;\n",tag,d1,d2,tag);
  // end float

  // If val type is string ----------------------

  // If val type is int ----------------------

  // If val type is char ----------------------

  cl.print(tmp);
}




Update, now converting the type to char before calling the PrintXML function resolves my initial issue. If I use the code below it seems to chew up a lot of memory, is there something obviously wrong? As a workaround I'm just printing the XML tags using cl.print and the memory usage is stable.

void PrintXMLTag(EthernetClient cl, char* tag,  char* val) 
{
  char tmp [100];
  sprintf(tmp,"&lt;%s&gt;%s&lt;/%s&gt;\n",tag,val,tag);
  cl.print(tmp);
  StrClear(tmp,100);
}
take a look at: http://www.cplusplus.com/doc/tutorial/functions2/

template &lt;typename SomeType&gt;
SomeType sum (SomeType a, SomeType b)
{
  return a+b;
}


This appears to be what you want.