help with passing parameters to a function

Hi all, I’m trying to create a function that accepts 3 parameters, the last parameter could be a string or integer, whats the best way to cater for both?
Also not sure if the below code is exactly correct, does using char* differ to char?

void PrintXMLTag(EthernetClient cl, char* tag, char* val) 
{
  char tmp;
  sprintf(tmp,"<%s>%s</%s>\n",*tag,val,*tag);
  cl.print(tmp);
}

Thank you

Hi all, I'm trying to create a function that accepts 3 parameters, the last parameter could be a string or integer, whats the best way to cater for both?

Do like everyone else, and write two different functions.

Of course, it's pretty simple to convert an int to a string, so you really only need to write one function.

  char tmp;
  sprintf(tmp,"<%s>%s</%s>\n",*tag,val,*tag);

That won’t compile, nor will it work. You need some sort of buffer, eg.

  char tmp [20];
  sprintf(tmp,"<%s>%s</%s>\n",*tag,val,*tag);

Where the “20” is large enough to hold your expected values.

By the way, tag is a string, so the %s would be appropriate. *tag is a character, so the %s is not.

Judging by what you are doing you want tag, then, like this:

  sprintf(tmp, "<%s>%s</%s>\n", tag, val, tag);

The buffer may need to be bigger if these are XML tags.

Thanks, Ive changed the code a little, but doesn’t seem to be working.

PrintXMLTag_NUM(cl,"test",analogRead(TempSensorPIN));

void PrintXMLTag_NUM(EthernetClient cl, String tag, int val) 
{
  char tmp [30];
  sprintf(tmp,"<%s>%s</%s>\n",tag,val,tag);  
  Serial.println(tmp);
}

Why did you suddenly switch to using String? What is the reason for that?

Thanks, Ive changed the code a little, but doesn't seem to be working.

Well, of course not. You'll need to look up what the C format specifier is for the C++ String class.

Here's a hint. There isn't one.